Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE SDFileSystem mbed-rtos mbed wave_player
main.cpp
- Committer:
- mikeb
- Date:
- 2016-02-26
- Revision:
- 0:e982498829af
- Child:
- 1:6553131e3bcf
File content as of revision 0:e982498829af:
#include "mbed.h"
// Need include below to add the RTOS
#include "rtos.h"
#include "SDFileSystem.h"
#include "uLCD_4DGL.h"
#include "wave_player.h"
#include "RGBLed.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
//wave player plays a *.wav file to D/A and a PWM
AnalogOut DACout(p18);
wave_player waver(&DACout);
uLCD_4DGL uLCD(p28,p27,p26); // serial tx, serial rx, reset pin;
SDFileSystem sd(p5, p6, p7, p8, "sd");
RGBLed rgb(p22, p23, p24);
Mutex uLCD_mutex;
Mutex seed_mutex;
volatile float seed = 0;
// Setup function code for three new threads to run.
// Put in a while loop so that threads run forever.
// Thread::wait will force at least a "x" millisecond
// wait before the thread runs again. During this delay
// the other threads will run
// DO NOT use wait() with the RTOS!!!!!
// wait just burns processor time and no other threads run
void audio_thread(void const *argument)
{
FILE *fp = fopen("/sd/mydir/Evil_Laugh.wav", "r");
if(fp == NULL) {
error("Could not open file for write\n");
}
while (true) {
waver.play(fp);
}
}
void uLCD2_thread(void const *argument)
{
float old_seed = 1;
while (true) {
if (old_seed != seed){
old_seed = seed;
uLCD_mutex.lock();
uLCD.filled_rectangle(20, 30, 100, 25,BLACK);
uLCD.filled_rectangle(20, 30, 100/seed, 25, RED);
uLCD_mutex.unlock();
}
}
}
void RGB_thread(void const *argument)
{
while (true) {
//seed_mutex.lock();
seed = rand()/float(RAND_MAX);
//seed_mutex.unlock();
rgb.write(seed*seed ,seed, seed*seed*seed); //Red, green, blue;
Thread::wait(200);
}
}
int main()
{
uLCD.cls();
uLCD.baudrate(3000000); //jack up baud rate to max for fast display
uLCD.text_width(2); //2x size text
uLCD.text_height(2);
uLCD.text_italic(ON);
uLCD.background_color(BLACK);
Thread thread1(uLCD2_thread);
Thread thread2(audio_thread);
Thread thread3(RGB_thread);
led1 = 1;
string s = "Spo";
std::string s2 = "oky!";
std::string o = " ";
std::string o2 = "o";
while (true) {
led2 = !led2;
for( short i = 0, i <6, i++){
uLCD_mutex.lock();
uLCD.locate(0,40);
uLCD.printf("%o%s%s2\n\r", o, s, s2);
uLCD_mutex.unlock();
o = o + " ";
Thread::wait(600);
}
o = " ";
for( short i = 0, i <6, i++){
uLCD_mutex.lock();
uLCD.locate(0,40);
uLCD.printf("%s%02%s2\n\r", s, o2, s2);
uLCD_mutex.unlock();
o2 = o2 + "o";
Thread::wait(600);
}
o2 = "o";
}
}