0% found this document useful (0 votes)
9 views

Lab10 Embedded

Uploaded by

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

Lab10 Embedded

Uploaded by

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

POST LAB TASK:

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <Arduino.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
#include <U8g2_for_Adafruit_GFX.h>

Adafruit_FT6206 ctp = Adafruit_FT6206();

//------------------------------
// Set the legs of the TFT screen.
#define TFT_DC 15
#define TFT_CS 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS,
TFT_DC);
#define BOXSIZE 40

//-------------------------------------------------
// Time unsigned long previousMillis =
0; unsigned long
previousMillis_Thingspeak = 0; const
long interval = 1000; const long
interval_Thingspeak = 20000;
//-------------------------------------------------
int led =
17; int
Count = 0;

//--------------------------------
// LGB bar
const int ledCount = 10; // the number of LEDs in the bar graph
int ledPins[]
= {
1, 2, 42, 41, 40, 35, 0, 45, 48, 47
}; // an array of pin numbers to which LEDs are
attached
//--------------------------------

U8G2_FOR_ADAFRUIT_GFX u8g2_for_adafruit_gfx;
void
setup() {
Serial.begin(115200);
while (!
Serial) {
; // wait for serial port to connect. Needed for Leonardo native
USB port only } pinMode(led, OUTPUT);

// loop over the pin array and set them all to


output: for (int thisLed = 0; thisLed < ledCount;
thisLed++) { pinMode(ledPins[thisLed], OUTPUT);
}

//Wire.setPins(10, 8);
tft.begin();

if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient


Serial.println("Couldn't start FT6206 touchscreen controller");
while (1);
} tft.setCursor(26,
120);
tft.setTextColor(ILI9341_RED)
; tft.setTextSize(3);
tft.println("Hello, Kazim!");
tft.setCursor(20, 160);
tft.setTextColor(ILI9341_GREEN)
; tft.setTextSize(2);
tft.println("I can has
colors?");

//delay(2000);
tft.fillScreen(ILI9341_BLACK);
tft.fillRect(0, 0, BOXSIZE, BOXSIZE,
ILI9341_WHITE); tft.setCursor(13, 18);
tft.setTextColor(ILI9341_RED);
tft.setTextSize(1); tft.println("ON!");

tft.fillRect(BOXSIZE+3, 0, BOXSIZE, BOXSIZE,


ILI9341_WHITE); tft.setCursor(53, 18);
tft.setTextColor(ILI9341_RED); tft.setTextSize(1);
tft.println("OFF!");

} void
loop() {

Touch(); for (int i = 0; i


<= 9; i++){
digitalWrite(ledPins[i], LOW);
}
} void
Touch(){

delay(10);
// Wait for a touch
if (! ctp.touched())
{ return;
}

TS_Point p = ctp.getPoint();

p.x = map(p.x, 0, 240, 240, 0);


p.y = map(p.y, 0, 320, 320, 0);

Serial.print("("); Serial.print(p.x);
Serial.print(", "); Serial.print(p.y);
Serial.println(")");
if (p.y <
BOXSIZE){ if
(p.x < 40){
digitalWrite(led, HIGH);
}
else if (p.x < 40*2){
digitalWrite(led, LOW);
}
else if (p.x < 40*3 || p.x <
40*4){ Count++;
if(Count > 1)
Count = 0;
}
}

}
IN LAB TASK 1:
CODE:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
// Declaration for an SSD1306 display connected to I2C (SDA,
SCL pins) Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT,
&Wire, -1); void setup() { Serial.begin(9600);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3D for
128x64 Serial.println(F("SSD1306 allocation failed")); for(;;); }
delay(2000);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE
); display.setCursor(0,
10); // Display static
text

display.println("Hello, world!");
display.display(); delay(3000);
display.clearDisplay(); display.setTextSize(1);
display.setTextColor(WHITE); display.setCursor(0,
20); // Display static text display.println("Hi
kazim mehdi here"); display.display();
delay(3000); display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE); display.setCursor(0,
30); // Display static text
display.println("Welcome to Embedded Systems
Workshop"); display.display();
} void
loop() {
}

IN LAB TASK 2:
/*
Display Name and Registration Number on ILI9341 LCD
*/

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void
setup()
{ tft.begi
n();

// Clear the screen with a black


background
tft.fillScreen(ILI9341_BLACK);
// Set cursor and print name
tft.setCursor(10, 100); // Adjust position as
needed tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(3);
tft.println("Kazim Mehdi");

// Set cursor and print registration number


tft.setCursor(10, 150); // Adjust position as
needed tft.setTextColor(ILI9341_CYAN);
tft.setTextSize(2);
tft.println("FA21-BCE-065");
} void
loop() {
// Nothing to do in the loop
}

CONCLUSION:
In this lab, we successfully utilized the ILI9341 TFT display to print a name and
registration number with distinct colors and text sizes, demonstrating text
formatting on the display. We explored cursor positioning, color settings, and text
scaling for effective output rendering. Additionally, we implemented touch screen
functionality for interactive controls and incorporated LED toggling through touch
inputs. The lab highlighted the integration of multiple components like TFT
displays and touch sensors, enhancing understanding of embedded system
capabilities. This foundational work supports further complex display and
interaction projects.

You might also like