int count = 0; int NoOfRelays = 5; int ir1 = 10; //int ir2 = 11; int toggleIR = 12; int relay1 = A0; int relay1status = false; int relay2 = A1; int relay2status = false; int relay3 = A2; int relay3status = false; int relay4 = A3; int relay4status = false; int relay5 = A4; int relay5status = false; // bits representing segments A through G (and decimal point) for numerals 0-9 const byte numeral[10] = { //ABCDEFG /dp B11111100, // 0 B01100000, // 1 B11011010, // 2 B11110010, // 3 B01100110, // 4 B10110110, // 5 B10111110, // 6 B11100000, // 7 B11111110, // 8 B11100110, // 9 }; // pins for decimal point and each segment // dp,G,F,E,D,C,B,A // common to 5v const int segmentPins[8] = { 5,9,8,7,6,4,3,2}; void setup() { pinMode(ir1,INPUT); // pinMode(ir2,INPUT); pinMode(relay1,OUTPUT); pinMode(relay2,OUTPUT); pinMode(relay3,OUTPUT); pinMode(relay4,OUTPUT); pinMode(relay5,OUTPUT); Serial.begin(9600); for(int i=0; i < 8; i++) { pinMode(segmentPins[i], OUTPUT); // set segment and DP pins to output } } void loop() { showDigit(count%10); int num = count%10; if(digitalRead(toggleIR) == 0){ switch (num){ case 1: relay1status = !relay1status; digitalWrite(relay1,relay1status); break; case 2: relay2status = !relay2status; digitalWrite(relay2,relay2status); break; case 3: relay3status = !relay3status; digitalWrite(relay3,relay3status); break; case 4: relay4status = !relay4status; digitalWrite(relay4,relay4status); break; case 5: relay5status = !relay5status; digitalWrite(relay5,relay5status); break; } } while(digitalRead(toggleIR)==0); delay(50); if(digitalRead(ir1)==0){ count++; delay(50); Serial.println(count); if(count>NoOfRelays){ count = 1; } } while(digitalRead(ir1)==0); delay(50); //if(digitalRead(ir2)==0){ // count--; // delay(50); // Serial.println(count); // // if(count<=0){ // count = 1; // } // //} // //while(digitalRead(ir2)==0); //delay(50); } // Displays a number from 0 through 9 on a 7-segment display void showDigit( int number) { boolean isBitSet; for(int segment = 1; segment < 8; segment++) { if( number < 0 || number > 9){ isBitSet = 0; // turn off all segments } else{ // isBitSet will be true if given bit is 1 isBitSet = bitRead(numeral[number], segment); } //isBitSet = ! isBitSet; // remove this line if common cathode display digitalWrite( segmentPins[segment], isBitSet); } }