Victor Szultka
/
2_1_Serial_Communications
Increase/decrease and LED brightness by PC command, and send a response to the PC via a terminal window.
main.cpp
- Committer:
- saltire78
- Date:
- 2020-07-31
- Revision:
- 0:8f9265fb1552
File content as of revision 0:8f9265fb1552:
#include"mbed.h" Serial pc(USBTX,USBRX);//tx,rx PwmOut led(LED1); float brightness=0.0; int main(){ pc.printf("Press 'u' to turn LED1 brightness up, 'd' to turn it down\n"); while(1){ char c =pc.getc(); if((c=='u')&&(brightness<0.5)){ brightness+=0.01; led=brightness; pc.putc('^');} if((c=='d')&&(brightness>0.0)){ brightness-=0.01; led=brightness; pc.putc('v');} } }