|
|
d |
|
|
\ No newline at end of file |
|
|
The task for this week is to use two input devices one digital and one analog to control two output devices, one of the output devices has to rely on a library to operate.
|
|
|
|
|
|
|
|
|
|
|
|
The two input devices used in this assignment are one RGB led and a push button. Whereas the output devices used are three potentiometer and a LCD Display.
|
|
|
|
|
|
First, we need to build the circuit first in TinkerCad and then physically with the Arduino Uno.
|
|
|
|
|
|
|
|
|
|
|
|
**1) Circuit**
|
|
|
|
|
|
We need the following components to build our circuit:-
|
|
|
|
|
|
· Microcontroller (Arduino Uno R3)
|
|
|
|
|
|
· 3 Potentiometer
|
|
|
|
|
|
· 3 Resistor of 220Ω
|
|
|
|
|
|
· 1 RGB Led
|
|
|
|
|
|
· 1 LCD Display(16x2)
|
|
|
|
|
|
· 1 Resistor of 300Ω
|
|
|
|
|
|
· 1 Push button
|
|
|
|
|
|
· 1 Resistor of 10 KΩ
|
|
|
|
|
|

|
|
|
|
|
|
At first RBG led was connected to our Arduino. RBG led have 4 pin, one for ground and the rest three for red, blue and green color. Carefully with the help of datasheet, the cathode(in my case ………) was joined to ground pin of the Arduino. Then all three color pins was connected to 220Ω resistor and to digital pin 11, 12, 13 respectively as shown in picture.
|
|
|
|
|
|
Then three different potentiometer was inserted into the breadboard to control the red, green and blue value of the led. The positive end of potentiometer is connected to 5V of the Arduino and negative to the ground pin. The middle pin, which gives the analog value we need is connected to analog pin(A0, A1, A2) of the Arduino to read the value. Thus with this circuit we will be able to change the red, green and blue value of the led with three different potentiometer.
|
|
|
|
|
|
LCD Display has 16 different pins for different purpose. The following table show the connected pin between LCD display and the Arduino.
|
|
|
|
|
|
<table>
|
|
|
<tr>
|
|
|
<td>
|
|
|
|
|
|
**LCD Display Pin No.**
|
|
|
</td>
|
|
|
<td>
|
|
|
|
|
|
**Arduino Pin No.**
|
|
|
</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>1 (GND)</td>
|
|
|
<td>GND</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>2 (VCC)</td>
|
|
|
<td>5V</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>3 (VD)</td>
|
|
|
<td>GND</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>4 (RS)</td>
|
|
|
<td>8</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>6 (E)</td>
|
|
|
<td>9</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>11 (DB4)</td>
|
|
|
<td>2</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>12 (DB5)</td>
|
|
|
<td>3</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>13 (DB6)</td>
|
|
|
<td>4</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>14 (DB7)</td>
|
|
|
<td>5</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>15 (LED +)</td>
|
|
|
<td>5V</td>
|
|
|
</tr>
|
|
|
<tr>
|
|
|
<td>16 (LED -) with resistor 300Ω in between</td>
|
|
|
<td>GND</td>
|
|
|
</tr>
|
|
|
</table>
|
|
|
|
|
|
|
|
|
|
|
|
For the push buttons, one pin was joined with 5V on the Arduino and another opposite pin was connected to the ground with resistor of 10 KΩ in between. The connected opposite pin from negative pin is connected to digital pin 6.
|
|
|
|
|
|
1) Code
|
|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
At first the necessary library was included. And then the digital pins for LEDs and analog pins were declared. The pin for button was also declared and the button-state variable with default value 0 was created to know the state of the button.
|
|
|
|
|
|
After that LCD pins were mapped to the Arduino pins. A custom heart shape is created for decoration.
|
|
|
|
|
|

|
|
|
|
|
|
In the setup method, we need to initialize our digital pins. Since we do not want to read the value but only turn on or off the LEDs, the three digital pins(11,12,13) of the LEDs will be initialized as output.
|
|
|
|
|
|
But we need to read the values of the push buttons to display the new RGB value. Thus digital pin 6 will be initialized as input.
|
|
|
|
|
|

|
|
|
|
|
|
At first the values from the three different potentiometer for the RGB is read with analogRead function. Since the potentiometer gives the value from 0 – 1023, the value must be mapped for the appropriate value for the RGB (0-255). After that the respective value is set for the RGB led.
|
|
|
|
|
|
Now we want to show the RGB value in LCD display when the button is pressed. For that we need to know if the button is pressed. So the if statement is used. When the button is pressed, at first the display is cleared for old values. Then the respective values of RGB is shown in the LCD Display in second row. The delay of 1 sec is used to debounce the push button. |
|
|
\ No newline at end of file |