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: mbed mbed-rtos wave_player_appbd 4DGL-uLCD-SE SDFileSystem
Revision 5:471ccc07dbaf, committed 2019-10-07
- Comitter:
- TCNoodleshop
- Date:
- Mon Oct 07 02:39:45 2019 +0000
- Parent:
- 4:79863d2ea5a0
- Commit message:
- Lab3Part4;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Mon Oct 07 02:39:45 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/4180_1/code/4DGL-uLCD-SE/#2cb1845d7681
--- a/C12832_lcd.lib Sun Sep 22 17:57:46 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/dreschpe/code/C12832_lcd/#c9afe58d786a
--- a/LCD_fonts.lib Sun Sep 22 17:57:46 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/dreschpe/code/LCD_fonts/#d0b7d7bf1f56
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SDFileSystem.lib Mon Oct 07 02:39:45 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/SDFileSystem/#c8f66dc765d4
--- a/main.cpp Sun Sep 22 17:57:46 2013 +0000
+++ b/main.cpp Mon Oct 07 02:39:45 2019 +0000
@@ -1,164 +1,102 @@
-// example to test the mbed Lab Board lcd lib with the mbed rtos
-// Pot1 changes the contrast
-// Pot2 changes the speed of the sin wave
-
#include "mbed.h"
#include "rtos.h"
-#include "Small_6.h"
-#include "Small_7.h"
-#include "Arial_9.h"
-#include "stdio.h"
-#include "C12832_lcd.h"
-
+#include "uLCD_4DGL.h"
+#include "SDFileSystem.h"
+#include "wave_player.h"
+#include "string.h"
-C12832_LCD LCD;
-AnalogIn Pot1(p19);
-AnalogIn Pot2(p20);
-PwmOut Speaker(p26);
-PwmOut RGBLED_r(p23);
-PwmOut RGBLED_g(p24);
-PwmOut RGBLED_b(p25);
-DigitalIn joyfire(p14);
-BusIn joy(p15,p12,p13,p16);
-BusOut leds(LED1,LED2,LED3,LED4);
+uLCD_4DGL uLCD(p9, p10, p11); // serial tx, serial rx, reset pin;
+SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+PwmOut Red(p21);
+PwmOut Green(p22);
+PwmOut Blue(p23);
+Serial pc(USBTX,USBRX);
+//Analog Out Jack
+AnalogOut DACout(p18);
+//On Board Speaker
+PwmOut PWMout(p26);
+
+wave_player waver(&DACout,&PWMout);
// mutex to make the lcd lib thread safe
Mutex lcd_mutex;
// Thread 1
-// print counter into first line and wait for 1 s
+// Increments counter on screen
void thread1(void const *args)
{
- int i;
+ int i = 0;
+
while(true) { // thread loop
+ pc.printf("Thread 1\n\r");
lcd_mutex.lock();
- LCD.locate(0,0);
- LCD.set_font((unsigned char*) Small_6);
- LCD.printf("Thread1 count: %d",i);
+ uLCD.locate(1,2);
+ uLCD.printf("%2D",i);
lcd_mutex.unlock();
i++;
- Thread::wait(1000);
+ Thread::wait(1000); // wait 1 s
}
}
// Thread 2
-// print counter into third line and wait for 0,5s
+// Plays tick sound
void thread2(void const *args)
{
- int k;
+ FILE *wave_file=fopen("/sd/mydir/sample.wav","r");
while(true) { // thread loop
- lcd_mutex.lock();
- LCD.locate(0,20);
- LCD.set_font((unsigned char*) Arial_9);
- LCD.printf("Thread 2 count : %d",k);
- lcd_mutex.unlock();
- k++;
- Thread::wait(500); // wait 0.5s
+ pc.printf("Thread 2\n\r");
+ waver.play(wave_file);
+ Thread::wait(1000); // wait 1s
}
}
// Thread 3
-// print a sin function in a small window
-// the value of pot 1 changes the speed of the sine wave
+// Flashes led between red and blue
void thread3(void const *args)
{
- int i,k,v;
- double s,a;
- k = 1;
- lcd_mutex.lock();
- LCD.rect(89,0,127,17,1);
- lcd_mutex.unlock();
- while(true) { // thread loop
- v = Pot1.read_u16(); // get value of pot 1
- lcd_mutex.lock();
- for (i=90; i<127; i++) {
- s = 8 * sin((long double)(i+k) /5); // pixel to print
- a = 8 * sin((long double)(i+k-1) /5); // old pixel to erase
- LCD.pixel(i,9 + (int)a ,0); // erase pixel
- LCD.pixel(i,9 + (int)s ,1); // print pixel
+ bool flag = 0;
+
+ while(true) { // main is the next thread
+ pc.printf("Thread 3\n\r");
+ flag = !flag;
+ if(flag == 0) // make led red
+ {
+ Red = 1;
+ Green = 0;
+ Blue = 0;
}
- LCD.copy_to_lcd(); // LCD.pixel does not update the lcd
- lcd_mutex.unlock();
- k++;
- Thread::wait(v/100); // value of pot1 / 100
+ else // make led blue
+ {
+ Red = 0;
+ Green = 0;
+ Blue = 1;
+ }
+ Thread::wait(500); // wait 0.5
}
}
-// Thread 4
-// input pot 2 and change the contrast of LCD
-void thread4(void const *args)
-{
- int k;
- while(true) { // thread loop
- k = Pot2.read_u16(); // get the value of poti 2
- k = k >> 10; // need only 6 bits for contrast
- lcd_mutex.lock();
- LCD.set_contrast(k);
- lcd_mutex.unlock();
- Thread::wait(500); // wait 0.5s
- }
-}
-// Thread 5
-// RGB LED
-void thread5(void const *args)
+int main()
{
- while(true) { // thread loop
- RGBLED_r = 0.5 + (rand() % 11)/20.0;
- RGBLED_g = 0.5 + (rand() % 11)/20.0;
- RGBLED_b = 0.5 + (rand() % 11)/20.0;
- Thread::wait(1667); // wait 1.5s
- }
-}
-// Thread 6
-// Speaker
-void thread6(void const *args)
-{
- while(true) { // thread loop
- Speaker.period(1.0/800.0);
- Speaker = 0.01;
- Thread::wait(1000); // wait 1.0s
- Speaker.period(1.0/969.0);
- Speaker = 0.01;
- Thread::wait(1000); // wait 1.0s
+ bool flag = 0;
+
+ Thread t1(thread1); //start thread1
+ //Thread t2(thread2); //start thread2
+ Thread t3(thread3); //start thread3
+
+ // Flashes screen background between red and blue
+ while(true) { // main is the next thread
+ pc.printf("Thread 4");
+ lcd_mutex.lock();
+ flag = !flag;
+ if(flag == 0)
+ {
+ uLCD.filled_circle(120, 60, 10, RED);
+ }
+ else
+ {
+ uLCD.filled_circle(120, 60, 10, BLUE);
+ }
+ lcd_mutex.unlock();
+ Thread::wait(500); // wait 0.5
}
}
-
-// Thread 7
-// Joystick controls onboard mbed LEDs
-void thread7(void const *args)
-{
- while(true) { // thread loop
- if (joyfire) {
- leds = 0xf;
- } else {
- leds = joy;
- }
- Thread::wait(200); // wait 0.25s
- }
-}
-
-
-
-int main()
-{
- int j;
- LCD.cls();
-
- Thread t1(thread1); //start thread1
- Thread t2(thread2); //start thread2
- Thread t3(thread3); //start thread3
- Thread t4(thread4); //start thread4
- Thread t5(thread5); //start thread5
- Thread t6(thread6); //start thread6
- Thread t7(thread7); //start thread7
-
- while(true) { // main is the next thread
- lcd_mutex.lock();
- LCD.locate(0,9);
- LCD.set_font((unsigned char*) Small_7);
- j = LCD.get_contrast(); // read the actual contrast
- LCD.printf("contrast : %d",j);
- lcd_mutex.unlock();
- Thread::wait(500); // wait 0.5s
- }
-}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player_appbd.lib Mon Oct 07 02:39:45 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/4180_1/code/wave_player_appbd/#b1cea7afcfd2