Initial commit

Dependencies:   MODSERIAL mbed

Committer:
bjornnijhuis
Date:
Wed Sep 23 12:40:53 2015 +0000
Revision:
0:79cb894e00f4
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bjornnijhuis 0:79cb894e00f4 1 #include "mbed.h"
bjornnijhuis 0:79cb894e00f4 2 #include "MODSERIAL.h"
bjornnijhuis 0:79cb894e00f4 3
bjornnijhuis 0:79cb894e00f4 4 Ticker output;
bjornnijhuis 0:79cb894e00f4 5
bjornnijhuis 0:79cb894e00f4 6 AnalogIn pot(A0);
bjornnijhuis 0:79cb894e00f4 7 DigitalOut led_r (LED_RED);
bjornnijhuis 0:79cb894e00f4 8 DigitalOut led_g (LED_GREEN);
bjornnijhuis 0:79cb894e00f4 9 DigitalOut led_b (LED_BLUE);
bjornnijhuis 0:79cb894e00f4 10
bjornnijhuis 0:79cb894e00f4 11 MODSERIAL pc(USBTX, USBRX);
bjornnijhuis 0:79cb894e00f4 12 const int baudrate = 115200; // Baudrate voor seriële verbinding
bjornnijhuis 0:79cb894e00f4 13 const int output_rate = 1000;
bjornnijhuis 0:79cb894e00f4 14
bjornnijhuis 0:79cb894e00f4 15 bool fn_go = false;
bjornnijhuis 0:79cb894e00f4 16
bjornnijhuis 0:79cb894e00f4 17 void serial_output()
bjornnijhuis 0:79cb894e00f4 18 {
bjornnijhuis 0:79cb894e00f4 19 fn_go = true;
bjornnijhuis 0:79cb894e00f4 20 led_r.write(false);
bjornnijhuis 0:79cb894e00f4 21
bjornnijhuis 0:79cb894e00f4 22 }
bjornnijhuis 0:79cb894e00f4 23
bjornnijhuis 0:79cb894e00f4 24 int main()
bjornnijhuis 0:79cb894e00f4 25 {
bjornnijhuis 0:79cb894e00f4 26 led_r.write(true);
bjornnijhuis 0:79cb894e00f4 27 led_g.write(false);
bjornnijhuis 0:79cb894e00f4 28 led_b.write(true);
bjornnijhuis 0:79cb894e00f4 29 output.attach_us(&serial_output,output_rate) ;
bjornnijhuis 0:79cb894e00f4 30 pc.baud(baudrate);
bjornnijhuis 0:79cb894e00f4 31 while (true) {
bjornnijhuis 0:79cb894e00f4 32 led_b.write(false);
bjornnijhuis 0:79cb894e00f4 33
bjornnijhuis 0:79cb894e00f4 34 if(fn_go) {
bjornnijhuis 0:79cb894e00f4 35 led_g.write(true);
bjornnijhuis 0:79cb894e00f4 36 float pot_val = pot.read();
bjornnijhuis 0:79cb894e00f4 37 pot_val = pot_val*4 - 2;
bjornnijhuis 0:79cb894e00f4 38 pc.printf("Potmeter value %.2f \n",pot_val);
bjornnijhuis 0:79cb894e00f4 39
bjornnijhuis 0:79cb894e00f4 40 fn_go = false;
bjornnijhuis 0:79cb894e00f4 41 }
bjornnijhuis 0:79cb894e00f4 42 }
bjornnijhuis 0:79cb894e00f4 43 }