Ciaran O'Malley
/
LAB_2_1_SerialComms
Lab 2.1
main.cpp
- Committer:
- ciaranom
- Date:
- 2020-07-27
- Revision:
- 1:d8d13815a008
- Parent:
- 0:72aa19bb1aec
File content as of revision 1:d8d13815a008:
#include "mbed.h" Serial pc(USBTX, USBRX); // tx, rx PwmOut led(LED1); float brightness = 0.0; int main() { pc.printf("Press '^' to turn LED1 brightness up, 'v' to turn it down\n"); while(1) { char a = pc.getc(); //a is a single value taken from the last cahracter from the input stream (stdin)- the keyboard pc.putc(a); //Outputs the character C on the stdout - TeraTerm in this case - Prints input from keyboard if((a == '^') && (brightness < 0.5)) { //Code unly increases to LEDs 50% LEDs max capacity as not to risk damaging the device brightness += 0.01; //increases brigness up in increaments of 0.01 - 50 total led = brightness; } //if((a == 'v') && (brightness > 0.0)) { brightness -= 0.01; led = brightness; } }