// this demo will show you how to use Grove - touch sensor to control a LED
// when the touch sensor was touched, the led will on
// otherwise led off
// Grove - Touch sensor connect to D3
// Grove - LED connect to D7
const int pinTouch = 3; // pin of button define here
const int pinLed = 7; // pin of led define here
void setup()
{
pinMode(pinTouch, INPUT); // set button INPUT
pinMode(pinLed, OUTPUT); // set led OUTPUT
}
void loop()
{
if(digitalRead(pinTouch)) // when button is pressed
{
digitalWrite(pinLed, HIGH); // led on
}
else
{
digitalWrite(pinLed, LOW);
}
delay(10);
}
Comments