Executive decision maker for the mbed NXP1768 Application board. Ask a question, and press the center joystick button. Uses a pushbutton, PWM speaker, mbed LEDs, RGB LED, LCD, and the C rand function.

Dependencies:   C12832_lcd LCD_fonts PinDetect mbed

Files at this revision

API Documentation at this revision

Comitter:
4180_1
Date:
Tue Feb 03 19:42:36 2015 +0000
Commit message:
ver 1.0

Changed in this revision

C12832_lcd.lib Show annotated file Show diff for this revision Revisions of this file
LCD_fonts.lib Show annotated file Show diff for this revision Revisions of this file
PinDetect.lib Show annotated file Show diff for this revision Revisions of this file
Speaker.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r af96f6744422 C12832_lcd.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832_lcd.lib	Tue Feb 03 19:42:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/C12832_lcd/#c9afe58d786a
diff -r 000000000000 -r af96f6744422 LCD_fonts.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LCD_fonts.lib	Tue Feb 03 19:42:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/dreschpe/code/LCD_fonts/#d0b7d7bf1f56
diff -r 000000000000 -r af96f6744422 PinDetect.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PinDetect.lib	Tue Feb 03 19:42:36 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/AjK/code/PinDetect/#cb3afc45028b
diff -r 000000000000 -r af96f6744422 Speaker.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Speaker.h	Tue Feb 03 19:42:36 2015 +0000
@@ -0,0 +1,19 @@
+#include "mbed.h"
+// new class to play a note on Speaker based on PwmOut class
+class Speaker
+{
+public:
+    Speaker(PinName pin) : _pin(pin) {
+// _pin(pin) means pass pin to the Speaker Constructor
+    }
+// class method to play a note based on PwmOut class
+    void PlayNote(float frequency, float duration, float volume) {
+        _pin.period(1.0/frequency);
+        _pin = volume/2.0;
+        wait(duration);
+        _pin = 0.0;
+    }
+
+private:
+    PwmOut _pin;
+};
\ No newline at end of file
diff -r 000000000000 -r af96f6744422 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Feb 03 19:42:36 2015 +0000
@@ -0,0 +1,87 @@
+//Executive Decision Maker for Mbed Application Board
+#include "mbed.h"
+#include "Speaker.h"
+#include "PinDetect.h" 
+#include "C12832_lcd.h"
+#include "Arial_9.h" //font for LCD
+#include <math.h> //needed for rand()
+
+DigitalOut myLed1(LED1); //Builtin LEDs
+DigitalOut myLed2(LED2);
+DigitalOut myLed3(LED3);
+DigitalOut myLed4(LED4);
+
+PinDetect pb1(p14); //Debounce pushbutton and use interrupts
+
+Speaker mySpeaker(p26); //PWM speaker to play notes
+
+Timer t; //use a hardware timer
+
+PwmOut r (p23); //RGB LED pins
+PwmOut g (p24);
+PwmOut b (p25);
+
+C12832_LCD lcd; //On board LCD display
+
+volatile int pbStatus = 0; //pb hit flag
+
+void pb1_hit_callback (void) //pb interrupt routine - a callback after debounce
+{
+    pbStatus = 1;
+}
+void funcD( int i) //display a binary number on mbed's 4 LEDs
+{
+    myLed1 = i &0x01;
+    myLed2 = (i>>1) & 0x01;
+    myLed3 = (i>>2) & 0x01;
+    myLed4 = (i>>3) & 0x01;
+}
+int main()
+{
+    unsigned int number=0;
+    //setup debounced pushbutton using interrupts
+    pb1.mode(PullDown);
+    wait(.01);
+    pb1.attach_asserted(&pb1_hit_callback);
+    pb1.setSampleFrequency();
+    //setup LCD prompt
+    lcd.cls();
+    lcd.set_font((unsigned char*) Arial_9);
+    lcd.printf("   Ask a Question, \n\r   then push Joystick");
+    //RGB LED init
+    b = 1.0; //blue 1.0=off 
+    //use a timer to generate seed for rand (different number to start each time)
+    t.start(); //start timer
+    while(pbStatus == 0) {}; //timer counts until pb hit
+    srand(t.read_ms()); //read ms from timer
+    while(1) {
+        if(pbStatus == 1) { //pb hit?
+            pbStatus = 0; //reset pb hit flag
+            lcd.cls();
+            lcd.locate(38,10);
+            //loop though several random numbers on LEDs and make beeps on Speaker
+            for(int i=0; i<24; ++i) {
+                number = (rand() % 16);
+                mySpeaker.PlayNote(200.0 * (number + 1), 0.1, 1.0);
+                funcD(number);
+            }
+            // Update RGB led:  Red, Yellow, or Green based on number
+            // Update LCD: No, Maybe, or Yes
+            b = 1.0;
+            if (number < 5) {
+                r = 0.8;
+                g = 1.0;
+                lcd.printf("  NO");
+            } else {
+                r = 0.8;
+                g = 0.8;
+                if (number <=10) lcd.printf(" MAYBE");
+                if (number > 10) {
+                    r = 1.0;
+                    lcd.printf(" YES");
+                }
+            }
+        }
+        wait(.05);
+    }
+}
diff -r 000000000000 -r af96f6744422 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Feb 03 19:42:36 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file