SWITCH BY REMOTE AND SEVEN SEGMENT DISPLAY

IR seven segmen

The code can be downloaded at:

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/REMOTE%20SWITCH%20WITH%20DISPLAY.zip

#include <IRremote.h>

int RECV_PIN = 7;

IRrecv irrecv(RECV_PIN);

decode_results results;

int ledPin1 = 6;

int ledPin2 = 5;

int ledPin3 = 4;

int ledPin4 = 3;

int index = -1; // to indicate which led should be turned on

int latchPin = 8;

int clockPin = 12;

int dataPin = 11;

byte leds = 0;

void setup() {

Serial.begin(9600);

Serial.print(“Sketch: “); Serial.println(__FILE__);

Serial.print(“Uploaded: “); Serial.println(__DATE__);

Serial.print(“Time Uploaded: “); Serial.println(__TIME__);

Serial.println(” “);

irrecv.enableIRIn(); // Start the receiver

pinMode(ledPin1, OUTPUT);

pinMode(ledPin2, OUTPUT);

pinMode(ledPin3, OUTPUT);

pinMode(ledPin4, OUTPUT);

pinMode(latchPin, OUTPUT);

pinMode(dataPin, OUTPUT);

pinMode(clockPin, OUTPUT);

}

unsigned long last = millis();

void loop() {

if (irrecv.decode(&results)) {

if (results.value == 0xEF1001FE) {

// the button is pushed

// turn off the LED which is on now

if(index != -1){ // if index is not the initial value

switch (index){

case 0:

digitalWrite(ledPin1, LOW); // turn the LED off (LOW is the voltage level)

delay(50);

break;

case 1:

digitalWrite(ledPin2, LOW);

delay(50);

break;

case 2:

digitalWrite(ledPin3, LOW);

delay(50);

break;

case 3:

digitalWrite(ledPin4, LOW);

delay(50);

break;

}

}

// turn on the next LED

index ++;

index = index % 5;

switch (index){

case 0:

digitalWrite(ledPin1, HIGH); // turn the LED on (HIGH is the voltage level)

leds = 0;//1

bitSet(leds, 0); //a

//bitSet(leds, 1); //b

//bitSet(leds, 2); //c

bitSet(leds, 3); //d

bitSet(leds, 4); //e

bitSet(leds, 5); //f

bitSet(leds, 6); //g

bitSet(leds, 7); //dp

updateShiftRegister();

delay(250);

break;

case 1:

digitalWrite(ledPin2, HIGH);

leds = 0;//2

//bitSet(leds, 0); //a

//bitSet(leds, 1); //b

bitSet(leds, 2); //c

//bitSet(leds, 3); //d

//bitSet(leds, 4); //e

bitSet(leds, 5); //f

//bitSet(leds, 6); //g

bitSet(leds, 7); //dp

updateShiftRegister();

delay(250);

break;

case 2:

digitalWrite(ledPin3, HIGH);

leds = 0;//3

//bitSet(leds, 0); //a

//bitSet(leds, 1); //b

//bitSet(leds, 2); //c

//bitSet(leds, 3); //d

bitSet(leds, 4); //e

bitSet(leds, 5); //f

//bitSet(leds, 6); //g

bitSet(leds, 7); //dp

updateShiftRegister();

delay(250);

break;

case 3:

digitalWrite(ledPin4, HIGH);

leds = 0;//4

bitSet(leds, 0); //a

//bitSet(leds, 1); //b

//bitSet(leds, 2); //c

bitSet(leds, 3); //d

bitSet(leds, 4); //e

//bitSet(leds, 5); //f

//bitSet(leds, 6); //g

bitSet(leds, 7); //dp

updateShiftRegister();

delay(250);

break;

case 4:

digitalWrite(ledPin1, LOW);

digitalWrite(ledPin2, LOW);

digitalWrite(ledPin3, LOW);

digitalWrite(ledPin4, LOW);

leds = 0;//blank

bitSet(leds, 0); //a

bitSet(leds, 1); //b

bitSet(leds, 2); //c

bitSet(leds, 3); //d

bitSet(leds, 4); //e

bitSet(leds, 5); //f

bitSet(leds, 6); //g

bitSet(leds, 7); //dp

updateShiftRegister();

delay(250);

break;

}

}

irrecv.resume(); // Receive the next value

}

}

void updateShiftRegister()

{

digitalWrite(latchPin, LOW);

shiftOut(dataPin, clockPin, MSBFIRST, leds);

//MSBFIRST is LED trigger from no 1

//LSBFIRST is LED trigger from no 8

digitalWrite(latchPin, HIGH);

}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s