C++ Code for the final project, to write input data from the joystick to the serial port through the mbed.

Dependencies:   mbed

Committer:
spoda
Date:
Mon Dec 12 04:46:52 2016 +0000
Revision:
0:173425de07bf
C++ Code for the final project, to write input data from the joystick to the serial port through the mbed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
spoda 0:173425de07bf 1 #include "mbed.h"
spoda 0:173425de07bf 2
spoda 0:173425de07bf 3 Serial pc(USBTX, USBRX);
spoda 0:173425de07bf 4 DigitalIn Up(p24);
spoda 0:173425de07bf 5 DigitalIn Left(p26);
spoda 0:173425de07bf 6 DigitalIn Right(p28);
spoda 0:173425de07bf 7 DigitalIn Down(p27);
spoda 0:173425de07bf 8
spoda 0:173425de07bf 9 int main() {
spoda 0:173425de07bf 10 while(1) {
spoda 0:173425de07bf 11 if (Up.read() == 0) {
spoda 0:173425de07bf 12 pc.printf("u\n");
spoda 0:173425de07bf 13 }
spoda 0:173425de07bf 14 else if (Down.read() == 0) {
spoda 0:173425de07bf 15 pc.printf("d\n");
spoda 0:173425de07bf 16 }
spoda 0:173425de07bf 17 else if (Left.read() == 0) {
spoda 0:173425de07bf 18 pc.printf("l\n");
spoda 0:173425de07bf 19 }
spoda 0:173425de07bf 20 else if (Right.read() == 0) {
spoda 0:173425de07bf 21 pc.printf("r\n");
spoda 0:173425de07bf 22 }
spoda 0:173425de07bf 23 wait(0.2);
spoda 0:173425de07bf 24 }
spoda 0:173425de07bf 25 }