Page 1 of 1

Program a board to respond to keyboard?

Posted: Wed May 27, 2015 10:49 am
by zigon
Hi,
I am new to electronics and just bought myself an freetronics experimenters kit,
Just wondering if i can press a key on my keyboards and it will say turn the piezo on?
Or is this not possible.

Thanks,
Simon

Re: Program a board to respond to keyboard?

Posted: Wed May 27, 2015 10:40 pm
by andrew
Connect your piezo to D8 and try the following:

Code: Select all

void setup()  
{
  // set digital pin to control as an output
  pinMode(8, OUTPUT);
  // set the data rate for the Serial port
  Serial.begin(9600);
  // Send test message to PC
  Serial.println("Hello, world.");
}
char a; // stores incoming character from PC
void loop() 
{
  if (Serial.available())
  // if text arrived in from BT serial...
  {
    a=(Serial.read());
    if (a=='1')
    {
    tone(8, 493, 1000);
      Serial.println("on");
    }
  }
}
When you send the number '1' from the Serial monitor (or other software on your PC that can send text down the USB port) the Eleven will respond by making a tone for one second.

For more information on how Serial works, visit:
http://www.arduino.cc/en/Reference/Serial

Re: Program a board to respond to keyboard?

Posted: Thu May 28, 2015 6:57 am
by zigon
thanks :)