Serial communication program

Dependencies:   mbed

Serial.cpp

Committer:
T00209563
Date:
2020-08-01
Revision:
0:2f8376278c8a

File content as of revision 0:2f8376278c8a:

#include "mbed.h"

Serial pc(USBTX,USBRX);   //defines an object called pc of serial class, and points it at the usb port
PwmOut led(LED1);        //pulse width modulation
float brightness = 0.0; //brightness ia a variable of type float


int main()
{
    pc.printf ("Press 'u' = brighter, 'd' = dimmer\n\r"); //outputs a message at the start

    while(1) {

        char c = pc.getc ();
        if (( c =='u') && (brightness < 0.5)) {
            brightness += 0.01;
            pc.putc('^');   // when U is pressed ^ is printed to the screen
            led = brightness;
        }
        if (( c =='d') && (brightness > 0.0)) {
            brightness -= 0.01;
            pc.putc('V');   // when d is pressed V is printed to the screen
            led = brightness;
        }

    }
}