/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */ #include int ledPins[] = { 2, 3, 4, 5, 6, 7, 8, 9 }; int buttonPin = 10; int servoPin = 11; int mode = 0; int ledCount = 0; int previousButton = LOW; Servo theServo; void setup() { //Serial.begin( 9600 ); for( int i = 0; i < 8; ++i ) { pinMode( ledPins[i], OUTPUT ); } pinMode( buttonPin, INPUT ); theServo.attach( 11 ); } void loop() { checkButton(); lightLeds(); moveServo(); delay( 50 ); } void checkButton( ) { int button = digitalRead( buttonPin ); if( button == LOW && previousButton == HIGH ) { buttonClicked(); } previousButton = button; } void buttonClicked() { ledCount = ledCount + 1; if( ledCount > 8 ) { ledCount = 0; } } void lightLeds() { for( int i = 0; i < ledCount; ++i ) { digitalWrite( ledPins[i], HIGH ); } for( int i = ledCount; i < 8; ++i ) { digitalWrite( ledPins[i], LOW ); } } void moveServo() { int degrees = map( ledCount, 0, 8, 7, 160 ); //Serial.println( "Led count: " ); /* Serial.print( "Led count: " ); Serial.print( ledCount ); Serial.print( " => Degrees: " ); Serial.print( degrees ); Serial.println( ); */ theServo.write( degrees ); delay( 15 ); }