/* Serial communication with the Arduino * using any serial communication application * Setup: -Wire an LED from digital pin 7 thru 330ohm resistor to gnd * -Piezo disk between digital pin 8 and Gnd */ byte inByte; int LEDpin = 7; void setup(){ Serial.begin(9600); // Begin serial communication pinMode(LEDpin, OUTPUT); // set digital pin 7 as input } void loop(){ if (Serial.available() > 0){ // only if serial data's there inByte = Serial.read(); // read it, store in inByte if (inByte == 49){ // if serial value = "1" key digitalWrite(LEDpin, HIGH); // light LED, otherwise tone(8, 440, 80); // syntax: tone(pin, freq, duration) } else if(inByte == 50){ // Key is "2" digitalWrite(LEDpin, HIGH); // light LED, otherwise tone(8, 640, 80); } else if (inByte == 0) { digitalWrite(LEDpin, LOW); // Otherwise, LED off } } } |