Serial communications

Dependencies:   mbed

main.cpp

Committer:
t00214916
Date:
2021-08-18
Revision:
0:aae7fead5990

File content as of revision 0:aae7fead5990:

#include "mbed.h"

PwmOut led(LED1);   // Pmw is defined as led
Serial pc(USBTX, USBRX);    // Used to communicate with PC


float brightness = 0.0;     // 

int main(){
    
    pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down \r\n");
    // Print on to PC via Teraterm
    
    while(1) {
        
        char c = pc.getc(); // getc looks for a character input
        if((c == 'u') && (brightness < 0.5)) {
            pc.putc('^'); // This prints ^ on teraterm
            brightness += 0.01;
            led = brightness;
        }
        if((c == 'd') && (brightness > 0.0)) {
            pc.putc('V');
            brightness -= 0.01;
            led = brightness;
        }
    }
}