-
Notifications
You must be signed in to change notification settings - Fork 0
/
arduinoserial_write.cpp
60 lines (53 loc) · 1.25 KB
/
arduinoserial_write.cpp
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
//TODO SEE IF YOU CAN SEND INFO SIMILAR TO THAT OF THE BLOB DETECTION PROGRAM OVER TO SERIAL AND HAVE THE ARM MOVE TO A DIRECTION LIKE THAT
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <unistd.h>
#include <fstream>
#include <stdlib.h>
#include <time.h>
using namespace std;
/*
int main()
{
int data[] = {10,5,13}; //Random data we want to send
FILE *file;
file = fopen("/dev/ttyACM0","w"); //Opening device file
if(file == NULL){
cout<<"LOL YOU SUCK"<<endl;
}
int i = 0;
for(i = 0 ; i < 3 ; i++)
{
fprintf(file,"%d",data[i]); //Writing to the file
fprintf(file,"%c",','); //To separate digits
sleep(1);
}
fclose(file);
}
*/
int posX;
int posY;
int main(){
while(1){
srand(time(NULL));
posX = rand() % 180;
posY = rand() % 180;
int coordinates[] = {posX, posY};
FILE *arduino;
arduino = fopen("/dev/ttyACM0", "w");
if(arduino == NULL){
cout<<"error: cannot connect to /dev/ttyACM0"<<endl;
}
int i = 0;
for(i =0; i<2; i++){
cout<<"sending info"<<endl;
fprintf(arduino, "%d", coordinates[i]);
fprintf(arduino, "%c", ',');
sleep(1);
}
cout<<"Info sent, I think"<<endl;
cout<<posX<<", "<<posY<<endl;
fclose(arduino);
}
}