RGB with push button and resistor array and a 7 segment LED display for the counter

I took the basic RGB push button configuration and added a twist a 7 segment LED display for the I2C Counter. My 30 days in Space project is a bit more complete

COMPONENTS AND SUPPLIES

RGB Led

1

ABOUT THIS PROJECT

It has grown beyond this setup.   I will post a newer picture later

You can see from this wiring diagram:
7 Segment LCD display connected to a SN74HC595 shift register:  3 wires to the UNO to control the display.
Above it the RGB LED with a push button using a 10K and 3 x 220 ohm resistorsThe I2C bus has 4 UNOs are slaves and a Mega 2560 as master.   I labeled them 1 to 5 from the bottom up.    As it increments it turns on its LED 13.

The I2C bus allows all devices to communication.   I have projects that go slave to master and master to slave.   I will be posting my photo resistor project with each UNO slave having a photoresistor and it sends the real time reading to the Mega to display on a LCD Screen.

The RGB code is

/*
* LED Mode Selection
* Pass a number for the LED state and set it accordingly
*/
void setMode(int mode)
{
//RED
if (mode == 1)
{
digitalWrite(RLED, HIGH);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
//GREEN
else if (mode == 2)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, HIGH);
digitalWrite(BLED, LOW);
}
//BLUE
else if (mode == 3)
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, HIGH);
}
//PURPLE (RED+BLUE)
else if (mode == 4)
{
analogWrite(RLED, 127);
analogWrite(GLED, 0);
analogWrite(BLED, 127);
}
//TEAL (BLUE+GREEN)
else if (mode == 5)
{
analogWrite(RLED, 0);
analogWrite(GLED, 127);
analogWrite(BLED, 127);
}
//ORANGE (GREEN+RED)
else if (mode == 6)
{
analogWrite(RLED, 127);
analogWrite(GLED, 127);
analogWrite(BLED, 0);
}
//WHITE (GREEN+RED+BLUE)
else if (mode == 7)
{
analogWrite(RLED, 85);
analogWrite(GLED, 85);
analogWrite(BLED, 85);
}
//OFF (mode = 0)
else
{
digitalWrite(RLED, LOW);
digitalWrite(GLED, LOW);
digitalWrite(BLED, LOW);
}
}

You can have some fun and add more color combinations.

The 7 Segment display code is posted later on.    I used a logic table to turn the x counter into the LCD number.   I will go through how to use logic tables in a future writeup.

CODE

				
					
				
			

SCHEMATICS

COMMENTS

Leave a Reply

Your email address will not be published. Required fields are marked *

/* Exploring Arduino – Code Listing 2-6: Toggling LED Nightlight http://www.exploringarduino.com/content/ch2 Copyright 2013 Jeremy Blum ( http://www.jeremyblum.com ) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License v3 as published by the Free Software Foundation. */ const int BLED=3; //Blue LED on Pin 9 const int GLED=5; //Green LED on Pin 10 const int RLED=6; //Red LED on Pin 11 const int BUTTON=2; //The Button is connected to pin 2 boolean lastButton = LOW; //Last Button State boolean currentButton = LOW; //Current Button State int ledMode = 0; //Cycle between LED states #include int LED = 13; // 8 segment LED for x counter int latchPin_7Segment=11; //white 595 pin 12 int clockPin_8Segment=9; //blue 595 pin 11 int dataPin_8Segment=12; //black 595 pin 14 // 8 segment LED for x counter // i2c counter int x = 0; int dt=250; // i2c counter // 8 segment LED for x counter byte LEDsOff=0b00000000; byte LEDsOn=0b11111111; byte LEDs1=0b10000000; byte LEDs2=0b01000000; byte LEDs3=0b00100000; byte LEDs4=0b00010000; byte LEDs5=0b00001000; byte LEDs6=0b00000100; byte LEDs7=0b00000010; byte LEDs8=0b00000001; byte LEDZero = 0b11111100; byte LEDOne = 0b01100000; byte LEDTwo = 0b11011010; byte LEDThree = 0b11110010; byte LEDFour = 0b01100110; byte LEDFive = 0b10110110; byte LEDSix = 0b00111110; // 8 segment LED for x counter void setup() { pinMode (BLED, OUTPUT); //Set Blue LED as Output pinMode (GLED, OUTPUT); //Set Green LED as Output pinMode (RLED, OUTPUT); //Set Red LED as Output pinMode (BUTTON, INPUT); //Set button as input (not required) pinMode (LED, OUTPUT); pinMode (latchPin_7Segment,OUTPUT); pinMode (dataPin_8Segment,OUTPUT); pinMode (clockPin_8Segment,OUTPUT); // Start the I2C Bus as Slave on address 4 Wire.begin(4); // Attach a function to trigger when something is received. Wire.onReceive(receiveEvent); } /* * LED Mode Selection * Pass a number for the LED state and set it accordingly */ void setMode(int mode) { //RED if (mode == 1) { digitalWrite(RLED, HIGH); digitalWrite(GLED, LOW); digitalWrite(BLED, LOW); } //GREEN else if (mode == 2) { digitalWrite(RLED, LOW); digitalWrite(GLED, HIGH); digitalWrite(BLED, LOW); } //BLUE else if (mode == 3) { digitalWrite(RLED, LOW); digitalWrite(GLED, LOW); digitalWrite(BLED, HIGH); } //PURPLE (RED+BLUE) else if (mode == 4) { analogWrite(RLED, 127); analogWrite(GLED, 0); analogWrite(BLED, 127); } //TEAL (BLUE+GREEN) else if (mode == 5) { analogWrite(RLED, 0); analogWrite(GLED, 127); analogWrite(BLED, 127); } //ORANGE (GREEN+RED) else if (mode == 6) { analogWrite(RLED, 127); analogWrite(GLED, 127); analogWrite(BLED, 0); } //WHITE (GREEN+RED+BLUE) else if (mode == 7) { analogWrite(RLED, 85); analogWrite(GLED, 85); analogWrite(BLED, 85); } //OFF (mode = 0) else { digitalWrite(RLED, LOW); digitalWrite(GLED, LOW); digitalWrite(BLED, LOW); } } /* * Debouncing Function * Pass it the previous button state, * and get back the current debounced button state. */ boolean debounce(boolean last) { boolean current = digitalRead(BUTTON); //Read the button state if (last != current) //if it’s different… { delay(5); //wait 5ms current = digitalRead(BUTTON); //read it again } return current; //return the current value } void receiveEvent(int bytes) { x = Wire.read(); // read one character from the I2C } // i2c counter void loop() { currentButton = debounce(lastButton); //read debounced state if (lastButton == LOW && currentButton == HIGH) //if it was pressed… { ledMode++; //increment the LED value } lastButton = currentButton; //reset button value //if you’ve cycled through the different options, reset the counter to 0 if (ledMode == 8) ledMode = 0; setMode(ledMode); /* // test all LED display digitalWrite(latchPin_7Segment,LOW); shiftOut(dataPin_8Segment,clockPin_8Segment,LSBFIRST,LEDsOn); digitalWrite(latchPin_7Segment,HIGH); delay(dt); */ // i2c counter if (x == 1) { //LED display digitalWrite(latchPin_7Segment,LOW); shiftOut(dataPin_8Segment,clockPin_8Segment,LSBFIRST,LEDOne); digitalWrite(latchPin_7Segment,HIGH); } if (x == 2) { digitalWrite(latchPin_7Segment,LOW); shiftOut(dataPin_8Segment,clockPin_8Segment,LSBFIRST,LEDTwo); digitalWrite(latchPin_7Segment,HIGH); } if (x == 3) { //LED display digitalWrite(latchPin_7Segment,LOW); shiftOut(dataPin_8Segment,clockPin_8Segment,LSBFIRST,LEDThree); digitalWrite(latchPin_7Segment,HIGH); } if (x == 4) { digitalWrite(latchPin_7Segment,LOW); shiftOut(dataPin_8Segment,clockPin_8Segment,LSBFIRST,LEDFour); digitalWrite(latchPin_7Segment,HIGH); } if (x == 5) { digitalWrite(LED, HIGH); //LED display digitalWrite(latchPin_7Segment,LOW); shiftOut(dataPin_8Segment,clockPin_8Segment,LSBFIRST,LEDFive); digitalWrite(latchPin_7Segment,HIGH); } else { digitalWrite(LED, LOW); } if (x == 6) { digitalWrite(LED, HIGH); // i2c counter // 8 segment LED for x counter digitalWrite(latchPin_7Segment,LOW); shiftOut(dataPin_8Segment,clockPin_8Segment,LSBFIRST,LEDSix); digitalWrite(latchPin_7Segment,HIGH); } /* //test rgb digitalWrite(RLED, LOW); delay(100); digitalWrite(RLED, HIGH); delay(200); digitalWrite(GLED, LOW); delay(100); digitalWrite(GLED, HIGH); delay(200); digitalWrite(BLED, LOW); delay(100); digitalWrite(BLED, HIGH); delay(200); */ }
PROJECT AUTHOR
Leave a comment
TEAM MEMBERS
SCSIraidGURU

Creator

TABLE OF CONTENTS
Leave a comment
Share on whatsapp
Share on facebook
Share on twitter
Share on linkedin
Share on reddit
Share on pinterest
Share on email

SIMILAR PROJECTS YOU MIGHT LIKE

I cascaded four SN74HC595 shift registers to control 32 LEDs on 4 registers using 3 wires. I am adding a I2C 20×4 LCD screen to display the register and led values. I might add a standard 16×2 LCD screen to show up it is done.
A simple light meter. It’s not calibrated to any meaningful scale, but the digital readout shows a higher number the brighter is the light falling on the photoresistor.
I got the Inventr Mega kit and started work on a lock for a door by using a 4×4 keypad, Uno, 20×4 LCD, and some resistors.