Advertisement
Guest User

Untitled

a guest
Jun 4th, 2014
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. by nupity
  2. int led = 3; // Pin 3
  3. void setup()
  4. {
  5. pinMode(led, OUTPUT); // Set pin 13 as digital out
  6. // Start up serial connection
  7. Serial.begin(9600); // baud rate
  8. Serial.flush();
  9. }
  10. void loop()
  11. {
  12. String input = "";
  13. // Read any serial input
  14. while (Serial.available() > 0)
  15. {
  16. input += (char) Serial.read(); // Read in one char at a time
  17. delay(5); // Delay for 5 ms so the next char has time to be received
  18. }
  19. if (input == "1") //if the arduino got "1" from the serial communication
  20. {
  21. digitalWrite(led, HIGH); // on
  22. }
  23. else if (input == "0") //if the arduino got "0" from the serial communication
  24. {
  25. digitalWrite(led, LOW); // off
  26. }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement