0% found this document useful (0 votes)
7 views4 pages

Lab7 Embedded

Uploaded by

omarkhaled999777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views4 pages

Lab7 Embedded

Uploaded by

omarkhaled999777
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab (7)

Name: tasneem mohamed mohamed


Sec: 1
ID:2100444
The simulation :-
Code in arduino:-
Code:-
#include <Adafruit_GFX.h> // Include the Adafruit Graphics Library
#include<Adafruit_ILI9341.h>
#include<SPI.h> // Include the SPI library for communication with the TFT display
#define R_PIN A5 // Define pin numbers for RGB inputs and TFT display control pins
#define G_PIN A4
#define B_PIN A3
#define display_CS 8
#define display_RST 9
#define display_DC 10
#define display_MISO 12
#define display_MOSI 11
#define display_CLK 13
Adafruit_ILI9341 Display =
Adafruit_ILI9341(display_CS,display_DC,display_MOSI,display_CLK,display_RST,display_MISO);
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud rate
Display.begin(); // Initialize the TFT display
}
void loop() {// Read analog input values from pins connected to RGB components
unsigned int R=analogRead(R_PIN);
unsigned int G=analogRead(G_PIN);
unsigned int B=analogRead(B_PIN);
B = B>>5;
G= (G>>4)<<5;
R= (R>>5)<<11;
unsigned long color = R+G+B; // Combine the color components to form a 16-bit color value
// Print the RGB values and the combined color value to serial monitor
Serial.print("R= "); Serial.println(R,DEC);
Serial.print("G= "); Serial.println(G,DEC);
Serial.print("B= "); Serial.println(B,DEC);
Serial.print("color= "); Serial.println(color,DEC);
Display.setCursor(10,150); // Set the cursor position on the TFT display
Display.setTextColor(color); // Set the text color on the TFT display
Display.setTextSize(3); // Set the text size on the TFT display
Display.println("Hello World"); // Print "Hello World" text on the TFT display with the
specified color
}

Idea:-
We have 16-bit:-
Bits 0:4 Blue Bits 5:10 Green Bits 11:15 Red
The decimal value range for each will be:
Blue 0:31 → 0001 1111 Green 0:63 → 0011 1111 Red 0:31 → 0001 1111
But the value range read from analogRead = 0:1023 → 0011 1111 1111
So, we need mapping between 1023 → 31 for Blue&Red. → Shift the analogRead value 5-bit for
Right.
1023 → 63 for Green → Shift the analogRead value 4-bit for Right.

For Blue:When shift the value [.e.g 0011 1111 1111] 5-bit for right will be [0001 1111] , so it
doesn’t need any other shifts because Blue bits 0:4.

For Green:When shift the value [.e.g 0011 1111 1111] 4-bit for right will be [0011 1111] , but
Green bits 5:10 ,So it need another shift to be at right position [0111 1110 0000] so, shift it 5-bit
for left.

For Red:Same as Blue , but it need another shift because its bits 11:15 So shift it 11-bit for left.

You might also like