0

Arduino workspace
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Arduino workspace

by dragonuv on Sun Mar 30, 2008 2:31 am

Hello, is there a way for me to use the digitalWrite() procedure using the send button and the textbox in the middle of the Arduino workspace?
dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

by mtbf0 on Sun Mar 30, 2008 9:52 am

not sure exactly what you want, but let's assume you want to type a zero or a one and have it turn on, (one), or turn off, (zero), an led with its anode connected to digital pin 3 of the arduino and its cathode connected to ground through an appropriately sized current limiting resistor.

first of all, the characters you have typed in the textbox will begin to show up on the arduino's usart interface, (think serial port), when you have clicked the send button or hit the enter key. in order to retrieve the character you use the arduino serial interface.

here's a little example that will accomplish what i outlined above.
Code: Select all | TOGGLE FULL SIZE
int foo;

void setup (void) {
  Serial.begin (9600);             // initialize serial interface, 9600 baud
  pinMode (3, OUTPUT);             // setup pin 3 as an output
}

void loop (void) {
  if (Serial.available()) {        // is data available on the USART
    foo = Serial.read ();
    if (foo == '0') digitalWrite (3, LOW);
    else if (foo == '1') digitalWrite (3, HIGH);
    else Serial.print (foo);       // yuck! spit it out
  }
}
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

by dragonuv on Sun Mar 30, 2008 1:16 pm

works great! thats what i wanted, thanks :)
dragonuv
 
Posts: 235
Joined: Tue Dec 04, 2007 1:22 pm

by mtbf0 on Sun Mar 30, 2008 1:51 pm

dragonuv wrote:works great! thats what i wanted, thanks :)


that's good, 'cuz i only had time to compile it, not to hook up a board and run it.
User avatar
mtbf0
 
Posts: 1645
Joined: Sat Nov 10, 2007 12:59 am
Location: oakland ca

Please be positive and constructive with your questions and comments.