Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int ledPins[] = { 13, 12, 11, 10, 7, 6, 5, 4, 3, 2 };
- int pinCount = 10;
- void setup()
- {
- int thisPin;
- for (int thisPin = 0; thisPin < pinCount; thisPin++) {
- pinMode(ledPins[thisPin], OUTPUT);
- }
- Serial.begin(57600);
- Serial.println("You know what to do.");
- }
- void loop() {
- static int val = 0;
- if (Serial.available())
- {
- int ch = Serial.read();
- switch(ch)
- {
- case '1'...'9':
- val = ch - '0';
- Serial.println(val);
- for (int thisPin = 0; thisPin < val; thisPin++) {
- // turn the pin on:
- digitalWrite(ledPins[thisPin], HIGH);}
- delay(1000);
- for (int thisPin = val - 1; thisPin >= 0; thisPin--) {
- // turn the pin off:
- digitalWrite(ledPins[thisPin], LOW);
- delay(1000);}
- flash();
- break;
- case 'x':
- Serial.println(10);
- for (int thisPin = 0; thisPin < 10; thisPin++) {
- digitalWrite(ledPins[thisPin], HIGH);}
- delay(1000);
- for (int thisPin = 10 - 1; thisPin >= 0; thisPin--) {
- digitalWrite(ledPins[thisPin], LOW);
- delay(1000);}
- flash();
- break;
- case '0':
- Serial.println("NOW");
- flash();
- }
- }
- val = 0;
- }
- void flash(){
- for (int i=0; i <= 3; i++){
- for (int thisPin = 0; thisPin < 10; thisPin++) {
- digitalWrite(ledPins[thisPin], HIGH);}
- delay(50);
- for (int thisPin = 10 - 1; thisPin >= 0; thisPin--) {
- digitalWrite(ledPins[thisPin], LOW);}
- delay(50);}
- }
Advertisement
Add Comment
Please, Sign In to add comment