-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherts-assignment.ino
More file actions
67 lines (56 loc) · 1.89 KB
/
erts-assignment.ino
File metadata and controls
67 lines (56 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <Servo.h>
#include <SPI.h>
#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
#define OLED_RESET 4
Adafruit_SSD1306 oled(screen_width, screen_height);
Servo myservo;
String myCmd;
void setup() {
Serial.begin(9600);
myservo.attach(9);
if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
while (true);
}
delay(2000); // wait for initializing
oled.clearDisplay(); // clear display
oled.setTextSize(1); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(0, 10); // position to display
oled.println(" COLOUR SORTER "); // text to display
oled.display(); // show on OLED
}
void loop() {
myCmd=Serial.readStringUntil('\r');
if(myCmd=="blue"){
myservo.write(0);
oled.setTextSize(1); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(15, 35); // position to display
oled.println(" COLOUR : BLUE "); // text to display
oled.display(); // show on OLED
delay(50);
}
if(myCmd=="green"){
myservo.write(90);
oled.setTextSize(1); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(15,35); // position to display
oled.println(" COLOUR : GREEN "); // text to display
oled.display(); // show on OLED
delay(50);
}
if(myCmd=="red"){
myservo.write(180);
oled.setTextSize(1); // text size
oled.setTextColor(WHITE); // text color
oled.setCursor(15,35); // position to display
oled.println(" COLOUR : RED "); // text to display
oled.display(); // show on OLED
delay(50);
}
}