-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnodeTest.ino
More file actions
76 lines (61 loc) · 1.7 KB
/
nodeTest.ino
File metadata and controls
76 lines (61 loc) · 1.7 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
68
69
70
71
72
73
74
75
76
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire);
#define NODE_SENSOR_A 2
#define NODE_SENSOR_B 3
#define NODE_SENSOR_C 3
#define NODE_SENSOR_D 4
int nodeCounter = 0;
int maxSpeed = 150;
void setup() {
Wire.begin();
if (!display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR)) {
Serial.println(F("SSD1306 allocation failed"));
for (;;);
}
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.display();
pinMode(NODE_SENSOR_A, INPUT);
pinMode(NODE_SENSOR_B, INPUT);
pinMode(NODE_SENSOR_C, INPUT);
pinMode(NODE_SENSOR_D, INPUT);
}
void readNode(){
int A = digitalRead(NODE_SENSOR_A);
int B = digitalRead(NODE_SENSOR_B);
int C = digitalRead(NODE_SENSOR_C);
int D = digitalRead(NODE_SENSOR_D);
int nodeValue = (A * 8) + (B * 4) + (C * 2) + D;
return nodeValue;
}
void detectNode(){
int nodeValue = readNode();
nodeCounter++;
if (nodeCounter == 1) {
maxSpeed = (nodeValue / 5.0) * 255;
} else if (nodeCounter == 2 && nodeValue == 0) {
maxSpeed = 255;
} else if (nodeCounter == 3) {
// angle = theta * 10
}
display.clearDisplay();
display.setCursor(10, 10);
display.print("Node detected!");
display.setCursor(10, 20);
display.setTextSize(2);
display.print("Node Value: ");
display.print(nodeValue);
display.setCursor(10, 40);
display.print("Node Count: ");
display.print(nodeCounter);
display.display();
delay(100);
}
void loop() {
}