Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. // Pin 13 has an LED connected on most Arduino boards.
  2. // give it a name:
  3. int ledRed = 13;
  4. int ledGreen = 12;
  5. int ledBlue = 11;
  6. int switchPin = 0;
  7. int switchState = LOW;
  8. // the setup routine runs once when you press reset:
  9. void setup() {
  10. // initialize the digital pin as an output.
  11. pinMode(ledRed, OUTPUT);
  12. pinMode(switchPin, INPUT);
  13. }
  14.  
  15. // the loop routine runs over and over again forever:
  16. void loop() {
  17. switchState = digitalRead(switchPin);
  18. if (switchState == LOW) { delayTime = 500; } else { delayTime = 250; }
  19. digitalWrite(ledRed, HIGH); // turn the LED on (HIGH is the voltage level)
  20. delay(delayTime); // wait for a second
  21. digitalWrite(ledRed, LOW); // turn the LED off by making the voltage LOW
  22. digitalWrite(ledGreen, HIGH); // turn the LED on (HIGH is the voltage level)
  23. delay(delayTime); // wait for a second
  24. digitalWrite(ledGreen, LOW); // turn the LED off by making the voltage LOW
  25. digitalWrite(ledBlue, HIGH); // turn the LED on (HIGH is the voltage level)
  26. delay(delayTime); // wait for a second
  27. digitalWrite(ledBlue, LOW); // turn the LED off by making the voltage LOW
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement