s
Dependencies: LM75B C12832_lcd LCD_fonts
main.cpp
- Committer:
- Lukas_Adlboller
- Date:
- 2019-11-19
- Revision:
- 0:e4434d058310
- Child:
- 1:133129bd3d45
File content as of revision 0:e4434d058310:
#include "mbed.h" #include "LM75B.h" #include "C12832_lcd.h" #include "MMA7660.h" DigitalOut startLED(LED3); DigitalOut rgbLED[] = {DigitalOut(p23), DigitalOut(p24), DigitalOut(p25)}; InterruptIn fireInterrupt(p14); Timeout startChecker; LM75B tempSensor(p28, p27); MMA7660 MMA(p28, p27); C12832_LCD lcdDisplay; Thread temp_thread; Thread gyro_thread; Mutex lcdMutex; bool boardStarted = false; bool tempThreadRunning = false; bool gyroThreadRunning = false; void tmpThread() { tempThreadRunning = true; while(boardStarted) { lcdMutex.lock(); lcdDisplay.cls(); lcdDisplay.locate(0, 0); lcdDisplay.printf("Temp: %.2f", tempSensor.read()); lcdMutex.unlock(); wait(0.5); } tempThreadRunning = false; } void gyroThread() { gyroThreadRunning = true; while(boardStarted) { int x = (x + MMA.x() * 32.0)/2.0; int y = (y -(MMA.y() * 16.0))/2.0; lcdMutex.lock(); lcdDisplay.fillcircle(x+83, y+15, 3, 1); //draw bubble lcdDisplay.circle(83, 15, 8, 1); lcdMutex.unlock(); wait(0.1); //time delay lcdMutex.lock(); lcdDisplay.fillcircle(x+83, y+15, 3, 0); //erase bubble lcdMutex.unlock(); } gyroThreadRunning = false; } void start() { if(boardStarted) { boardStarted = false; rgbLED[0] = 0; rgbLED[1] = 1; } else { boardStarted = true; rgbLED[0] = 1; rgbLED[1] = 0; } } void pressButton() { startChecker.attach(&start, 3.0); } void releaseButton() { startChecker.detach(); } int main() { rgbLED[0] = rgbLED[1] = rgbLED[2] = 1; rgbLED[0] = 0; rgbLED[1] = 1; fireInterrupt.rise(pressButton); fireInterrupt.fall(releaseButton); lcdDisplay.set_font((unsigned char*) Arial_9); while(1) { if(boardStarted && !tempThreadRunning) { temp_thread.start(tmpThread); } if(boardStarted && !gyroThreadRunning) { gyro_thread.start(gyroThread); } if(!boardStarted) { lcdMutex.lock(); lcdDisplay.cls(); lcdMutex.unlock(); } } }