Lukas Adlboller
/
4CHEL_FSST_Test
FSST Test
main.cpp
- Committer:
- Lukas_Adlboller
- Date:
- 2020-01-28
- Revision:
- 0:90f7dbc52b88
File content as of revision 0:90f7dbc52b88:
#include "mbed.h" Thread ledThread; DigitalOut led(LED2); Serial serialPC(USBTX, USBRX, 9600); Mutex dutyCycleMutex; const int period = 20; // ms int dutyCycle = 50; // % void ledOutput() { while(true) { if(dutyCycle != 0) { dutyCycleMutex.lock(); float onTime = (dutyCycle / 100.0f) * period; dutyCycleMutex.unlock(); led = 1; ThisThread::sleep_for(onTime); led = 0; ThisThread::sleep_for(period - onTime); } } } int main() { ledThread.start(ledOutput); while(true) { dutyCycleMutex.lock(); serialPC.printf("Duty: %d\n", dutyCycle); dutyCycleMutex.unlock(); char currentChar = serialPC.getc(); if(currentChar == 'Z') { dutyCycleMutex.lock(); dutyCycle = 0; dutyCycleMutex.unlock(); } else if(currentChar >= '1' && currentChar <= '9') { dutyCycleMutex.lock(); dutyCycle = (currentChar - '0') * 10; dutyCycleMutex.unlock(); } else if(currentChar == 'F') { dutyCycleMutex.lock(); dutyCycle = 100; dutyCycleMutex.unlock(); } } }