fun fork test of fun fork things

Dependencies:   mbed wave_player mbed-rtos 4DGL-uLCD-SE SDFileSystem

Committer:
cheryldocherty
Date:
Sat Apr 11 13:19:02 2020 +0000
Revision:
3:48862145678b
Parent:
2:7828936faad6
fork 1 with third space

Who changed what in which revision?

UserRevisionLine numberNew contents of line
cheryldocherty 3:48862145678b 1
cheryldocherty 2:7828936faad6 2
cheryldocherty 1:40788af73d41 3
cheryldocherty 0:97120df18654 4 #include "mbed.h"
cheryldocherty 0:97120df18654 5 #include "rtos.h"
cheryldocherty 0:97120df18654 6 #include "uLCD_4DGL.h"
cheryldocherty 0:97120df18654 7 #include "SDFileSystem.h"
cheryldocherty 0:97120df18654 8 #include "wave_player.h"
cheryldocherty 0:97120df18654 9
cheryldocherty 0:97120df18654 10 // Onboard LEDs (for testing)
cheryldocherty 0:97120df18654 11 DigitalOut led1(LED1);
cheryldocherty 0:97120df18654 12 DigitalOut led2(LED2);
cheryldocherty 0:97120df18654 13 DigitalOut led3(LED3);
cheryldocherty 0:97120df18654 14 DigitalOut led4(LED4);
cheryldocherty 0:97120df18654 15
cheryldocherty 0:97120df18654 16 // RBG LED
cheryldocherty 0:97120df18654 17 PwmOut RGBLED_r(p23);
cheryldocherty 0:97120df18654 18 PwmOut RGBLED_g(p24);
cheryldocherty 0:97120df18654 19 PwmOut RGBLED_b(p25);
cheryldocherty 0:97120df18654 20
cheryldocherty 0:97120df18654 21 // LCD Screen
cheryldocherty 0:97120df18654 22 uLCD_4DGL uLCD(p9,p10,p17); // serial tx, serial rx, reset pin;
cheryldocherty 0:97120df18654 23
cheryldocherty 0:97120df18654 24 Thread thread1;
cheryldocherty 0:97120df18654 25 Thread thread2;
cheryldocherty 0:97120df18654 26 Thread thread3;
cheryldocherty 0:97120df18654 27
cheryldocherty 0:97120df18654 28 // mutex to make the lcd lib thread safe
cheryldocherty 0:97120df18654 29 Mutex lcd_mutex;
cheryldocherty 0:97120df18654 30
cheryldocherty 0:97120df18654 31 //SD Card
cheryldocherty 0:97120df18654 32 SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
cheryldocherty 0:97120df18654 33
cheryldocherty 0:97120df18654 34 AnalogOut DACout(p18);
cheryldocherty 0:97120df18654 35
cheryldocherty 0:97120df18654 36 wave_player waver(&DACout);
cheryldocherty 0:97120df18654 37
cheryldocherty 0:97120df18654 38 //Bouncing Ball Demo
cheryldocherty 0:97120df18654 39 float fx=60.0,fy=60.0,vx=1.0,vy=0.4;
cheryldocherty 0:97120df18654 40 int x=60,y=60,radius=4;
cheryldocherty 0:97120df18654 41 int i = 0;
cheryldocherty 0:97120df18654 42
cheryldocherty 0:97120df18654 43 void led2_thread() {
cheryldocherty 0:97120df18654 44 while (true) {
cheryldocherty 0:97120df18654 45 lcd_mutex.lock();
cheryldocherty 0:97120df18654 46 //erase old ball location
cheryldocherty 0:97120df18654 47 uLCD.filled_circle(x, y, radius, BLACK);
cheryldocherty 0:97120df18654 48 //move ball
cheryldocherty 0:97120df18654 49 fx=fx+vx;
cheryldocherty 0:97120df18654 50 fy=fy+vy;
cheryldocherty 0:97120df18654 51 x=(int)fx;
cheryldocherty 0:97120df18654 52 y=(int)fy;
cheryldocherty 0:97120df18654 53 //draw ball
cheryldocherty 0:97120df18654 54 uLCD.filled_circle(x, y, radius, RED);
cheryldocherty 0:97120df18654 55 lcd_mutex.unlock();
cheryldocherty 0:97120df18654 56 //bounce off edge walls and slow down a bit?
cheryldocherty 0:97120df18654 57 if ((x<=radius+1) || (x>=126-radius)) vx = -.90*vx;
cheryldocherty 0:97120df18654 58 if ((y<=radius+51) || (y>=126-radius)) vy = -.90*vy;
cheryldocherty 0:97120df18654 59 Thread::wait(40);
cheryldocherty 0:97120df18654 60 }
cheryldocherty 0:97120df18654 61 }
cheryldocherty 0:97120df18654 62
cheryldocherty 0:97120df18654 63 void led3_thread() {
cheryldocherty 0:97120df18654 64 while (true) {
cheryldocherty 0:97120df18654 65 lcd_mutex.lock();
cheryldocherty 0:97120df18654 66 uLCD.locate(1,3);
cheryldocherty 0:97120df18654 67 uLCD.printf("%2D",i);
cheryldocherty 0:97120df18654 68 lcd_mutex.unlock();
cheryldocherty 0:97120df18654 69 i++;
cheryldocherty 0:97120df18654 70 Thread::wait(1000);
cheryldocherty 0:97120df18654 71 }
cheryldocherty 0:97120df18654 72 }
cheryldocherty 0:97120df18654 73
cheryldocherty 0:97120df18654 74 void led4_thread() {
cheryldocherty 0:97120df18654 75 while(true) { // thread loop
cheryldocherty 0:97120df18654 76 RGBLED_r = 0.5 + (rand() % 11)/20.0;
cheryldocherty 0:97120df18654 77 RGBLED_g = 0.1 + (rand() % 11)/20.0;
cheryldocherty 0:97120df18654 78 RGBLED_b = 0.1 + (rand() % 11)/20.0;
cheryldocherty 0:97120df18654 79 Thread::wait(40);
cheryldocherty 0:97120df18654 80 }
cheryldocherty 0:97120df18654 81 }
cheryldocherty 0:97120df18654 82
cheryldocherty 0:97120df18654 83 int main() {
cheryldocherty 0:97120df18654 84 thread1.start(led2_thread);
cheryldocherty 0:97120df18654 85 thread2.start(led3_thread);
cheryldocherty 0:97120df18654 86 thread3.start(led4_thread);
cheryldocherty 0:97120df18654 87
cheryldocherty 0:97120df18654 88 lcd_mutex.lock();
cheryldocherty 0:97120df18654 89 //draw walls
cheryldocherty 0:97120df18654 90 uLCD.line(0, 50, 127, 50, WHITE);
cheryldocherty 0:97120df18654 91 uLCD.line(127, 50, 127, 127, WHITE);
cheryldocherty 0:97120df18654 92 uLCD.line(127, 127, 0, 127, WHITE);
cheryldocherty 0:97120df18654 93 uLCD.line(0, 127, 0, 50, WHITE);
cheryldocherty 0:97120df18654 94 uLCD.locate(0,1);
cheryldocherty 0:97120df18654 95 uLCD.printf("Seconds Since \nInitialisation: "); //Default Green on black text
cheryldocherty 0:97120df18654 96 lcd_mutex.unlock();
cheryldocherty 0:97120df18654 97
cheryldocherty 0:97120df18654 98 FILE *wave_file;
cheryldocherty 0:97120df18654 99 printf("\n\n\nHello, wave world!\n");
cheryldocherty 0:97120df18654 100 wave_file=fopen("/sd/OriginalSeriesMainTitle.wav","r");
cheryldocherty 0:97120df18654 101 waver.play(wave_file);
cheryldocherty 0:97120df18654 102 fclose(wave_file);
cheryldocherty 0:97120df18654 103 while (true) {
cheryldocherty 0:97120df18654 104 led1 = !led1;
cheryldocherty 0:97120df18654 105
cheryldocherty 0:97120df18654 106
cheryldocherty 0:97120df18654 107 Thread::wait(500);
cheryldocherty 0:97120df18654 108 }
cheryldocherty 0:97120df18654 109 }