-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
arduino.c
72 lines (57 loc) · 1.33 KB
/
arduino.c
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
#define PIN_X 9
#define PIN_Y 3
#define PIN_LDR A0
void setup()
{
pinMode(PIN_X, OUTPUT);
pinMode(PIN_Y, OUTPUT);
pinMode(PIN_LDR, INPUT);
Serial.begin(115200);
delay(100);
Serial.println("Jesus Amor");
}
int delayTime = 23;
int limit = 256;
int increment = 1;
void loop()
{
if (Serial.available() > 0)
{
String command = Serial.readStringUntil('\n');
command.trim();
char receivedChars[256];
memset(receivedChars, '\0', 256);
command.toCharArray(receivedChars, 256);
// Read line.
if (strstr(receivedChars, "read:"))
{
char *ptr = &receivedChars[ strlen("read:") ];
char currentYCh[256];
int currentY = 0;
memset(currentYCh, '\0', 256);
for (int a=0; ptr[a]!='\0' && ptr[a]!='\n'; a++)
{
if (ptr[a] == '-')
{
currentY = atoi(currentYCh);
break;
}
currentYCh[a] = ptr[a];
}
// Control: X, Y.
Serial.print("startline");
analogWrite(PIN_Y, currentY);
delay(50);
for (int x=0; x<limit; x+=increment)
{
analogWrite(PIN_X, x);
delay(delayTime);
int LDR = analogRead(PIN_LDR) / 4;
Serial.print(LDR, DEC);
Serial.print(",");
}
Serial.print("endline");
delay(100);
}
}
}