int delay_value = 500; int filter_delay = 200; const int kled_pin = 9; //a 1 second delay between blinks, pin 9 to handle analog input const int kcycleButton = 12; //digital pin 12 pushed repeatedly to indicate number of blinks const int kbutton1 = 7; //digital pin 7 const int kbutton2 = 4; //digital pin 4 const int kbutton3 = 2; //digital pin 2 const int kconfirmButton = 13; //digital pin 13 //button must be pushed to start cycles int cycles_r = 0; //the number of running cycles int percent = 0; //the intensity of the LED String pass=""; void setup() { pinMode(kled_pin, OUTPUT); pinMode(kcycleButton, INPUT); pinMode(kbutton1, INPUT); pinMode(kbutton2, INPUT); pinMode(kbutton3, INPUT); pinMode(kconfirmButton, INPUT); Serial.begin(9600); } void loop() { while( digitalRead(kconfirmButton) != 1) { //count the number of cycles chosen counter_cycles(); //select the intensity of the LED output select_percent(); } //run the routine run_routine(); } void counter_cycles() { //check to see how many time cycleButton is pushed if ( digitalRead(kcycleButton) == 1) { delay(filter_delay); cycles_r = cycles_r + 1; //cycles_r++; Serial.println(pass+"Cycles= " + cycles_r); while (digitalRead(kcycleButton) == 1) {} } } void select_percent() //choose the intensity of the output { // intensity 10% if ( digitalRead(kbutton1) == 1) { delay (filter_delay); percent = 25; } // intensity 50% if ( digitalRead(kbutton2) == 1) { delay (filter_delay); percent = 128; } // intensity 100% if ( digitalRead(kbutton3) == 1) { delay (filter_delay); percent = 255; } } void run_routine() { Serial.println(pass+"Run " + cycles_r + " times with " + percent+ " % of intensity"); for (int i = 1; i<= cycles_r; i++) { //Activate PWM analogWrite(kled_pin, percent); delay(delay_value); //turn off LED digitalWrite(kled_pin, 0); delay(delay_value); } //Reset Cycles & Percent cycles_r = 0; percent = 0; }