Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string.h>
- #include <fcntl.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <termios.h>
- #include <unistd.h>
- //this code sends characters to the arduino and RoboKun listens..
- int main() {
- int arduino = open("/dev/ttyACM0", O_RDWR | O_NOCTTY | O_NDELAY);
- if (arduino == -1) {
- perror("Is the Arduino Connected?");
- return 1;
- }
- struct termios options;
- tcgetattr(arduino, &options);
- cfsetispeed(&options, B9600);
- cfsetospeed(&options, B9600);
- options.c_cflag |= (CLOCAL | CREAD);
- tcsetattr(arduino, TCSANOW, &options);
- char w='w';
- char a='a';
- char s='s';
- char d='d';
- char b='b';
- int dtime=5;
- char keystrokes[] = "b";
- keystrokes[0]=w;
- printf("Forward\n");
- write(arduino, keystrokes, strlen(keystrokes));
- sleep(dtime);
- keystrokes[0] = d;
- printf("Right\n");
- write(arduino, keystrokes, strlen(keystrokes));
- sleep(dtime);
- keystrokes[0] = a;
- printf("LEft\n");
- write(arduino, keystrokes, strlen(keystrokes));
- sleep(dtime);
- keystrokes[0] = s;
- printf("Reverse\n");
- write(arduino, keystrokes, strlen(keystrokes));
- sleep(dtime);
- keystrokes[0] = b;
- printf("halt\n");
- write(arduino, keystrokes, strlen(keystrokes));
- sleep(1);
- close(arduino);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement