int light = 8;
void setup()
{
pinMode(light, OUTPUT);
Serial.begin(9600);
while (!Serial);
}
void loop() {
if (Serial.available())
{
int state = Serial.parseInt();
if (state == 1)
{
digitalWrite(light, HIGH);
Serial.println("ON");
}
if (state == 2)
{
digitalWrite(light, LOW);
Serial.println("OFF");
}
}
}
Comments