![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
s
Dependencies: LM75B C12832_lcd LCD_fonts
main.cpp
- Committer:
- Lukas_Adlboller
- Date:
- 2019-12-06
- Revision:
- 1:133129bd3d45
- Parent:
- 0:e4434d058310
- Child:
- 2:b4a812174f7e
File content as of revision 1:133129bd3d45:
#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.locate(0, 20); lcdDisplay.printf("X: %d; Y: %d", x, y); 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(); } } }