Hertz Controle

Dependencies:   mbed

Committer:
ABuche
Date:
Sun Apr 15 16:16:56 2018 +0000
Revision:
0:f101b014b4a1
Initial commit;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ABuche 0:f101b014b4a1 1 #include "mbed.h"
ABuche 0:f101b014b4a1 2
ABuche 0:f101b014b4a1 3 /*------------------------------------------------------------------------------
ABuche 0:f101b014b4a1 4 Before to use this example, ensure that you an hyperterminal installed on your
ABuche 0:f101b014b4a1 5 computer. More info here: https://developer.mbed.org/handbook/Terminals
ABuche 0:f101b014b4a1 6
ABuche 0:f101b014b4a1 7 The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their
ABuche 0:f101b014b4a1 8 definition in the PinNames.h file).
ABuche 0:f101b014b4a1 9
ABuche 0:f101b014b4a1 10 The default serial configuration in this case is 9600 bauds, 8-bit data, no parity
ABuche 0:f101b014b4a1 11
ABuche 0:f101b014b4a1 12 If you want to change the baudrate for example, you have to redeclare the
ABuche 0:f101b014b4a1 13 serial object in your code:
ABuche 0:f101b014b4a1 14
ABuche 0:f101b014b4a1 15 Serial pc(SERIAL_TX, SERIAL_RX);
ABuche 0:f101b014b4a1 16
ABuche 0:f101b014b4a1 17 Then, you can modify the baudrate and print like this:
ABuche 0:f101b014b4a1 18
ABuche 0:f101b014b4a1 19 pc.baud(115200);
ABuche 0:f101b014b4a1 20 pc.printf("Hello World !\n");
ABuche 0:f101b014b4a1 21 ------------------------------------------------------------------------------*/
ABuche 0:f101b014b4a1 22
ABuche 0:f101b014b4a1 23 //Serial pc(PA_9, PA_10);
ABuche 0:f101b014b4a1 24
ABuche 0:f101b014b4a1 25 Serial regis(PA_10, PA_11);
ABuche 0:f101b014b4a1 26
ABuche 0:f101b014b4a1 27 DigitalOut led(LED1);
ABuche 0:f101b014b4a1 28 DigitalOut led2(LED2);
ABuche 0:f101b014b4a1 29
ABuche 0:f101b014b4a1 30 int main()
ABuche 0:f101b014b4a1 31 {
ABuche 0:f101b014b4a1 32 const int bufferSize = 1024;
ABuche 0:f101b014b4a1 33 int * buffer = new int [bufferSize];
ABuche 0:f101b014b4a1 34 int i = 1;
ABuche 0:f101b014b4a1 35 char c = 'w';
ABuche 0:f101b014b4a1 36 //pc.printf("Hello World !\n");
ABuche 0:f101b014b4a1 37 led = 0;
ABuche 0:f101b014b4a1 38 led2= 0;
ABuche 0:f101b014b4a1 39 while(1) {
ABuche 0:f101b014b4a1 40 //pc.printf("This program runs since %d seconds.\r\n", i++);
ABuche 0:f101b014b4a1 41 c = regis.getc();
ABuche 0:f101b014b4a1 42 if (c == 'w'){
ABuche 0:f101b014b4a1 43 led = 1;
ABuche 0:f101b014b4a1 44 } else{
ABuche 0:f101b014b4a1 45 led2 = 1;
ABuche 0:f101b014b4a1 46 }
ABuche 0:f101b014b4a1 47 //pc.printf("Char: %c", c);
ABuche 0:f101b014b4a1 48 //if(regis.readable()){
ABuche 0:f101b014b4a1 49 // pc.printf("Woooooow\r\n");
ABuche 0:f101b014b4a1 50 //}
ABuche 0:f101b014b4a1 51 i++;
ABuche 0:f101b014b4a1 52 if(i % 10 == 0){
ABuche 0:f101b014b4a1 53 led2 = !led2;
ABuche 0:f101b014b4a1 54 }
ABuche 0:f101b014b4a1 55 }
ABuche 0:f101b014b4a1 56 }