a small song

Dependencies:   C12832 LM75B MMA7660 mbed

Files at this revision

API Documentation at this revision

Comitter:
tyli
Date:
Mon Feb 16 09:11:32 2015 +0000
Commit message:
20150213Friday

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
LM75B.lib Show annotated file Show diff for this revision Revisions of this file
MMA7660.lib 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
main.h 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
morse.cpp Show annotated file Show diff for this revision Revisions of this file
morse.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 9d7b581da110 C12832.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Mon Feb 16 09:11:32 2015 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/chris/code/C12832/#7de323fa46fe
diff -r 000000000000 -r 9d7b581da110 LM75B.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LM75B.lib	Mon Feb 16 09:11:32 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/neilt6/code/LM75B/#fc27dc535ea9
diff -r 000000000000 -r 9d7b581da110 MMA7660.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA7660.lib	Mon Feb 16 09:11:32 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/Sissors/code/MMA7660/#36a163511e34
diff -r 000000000000 -r 9d7b581da110 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Feb 16 09:11:32 2015 +0000
@@ -0,0 +1,133 @@
+#include "main.h"
+#include "morse.h"
+
+#define DO 0.003822258
+#define RE 0.003405245
+#define MI 0.003033728
+#define FA 0.002863458
+#define SO 0.002551050
+#define LA 0.002272727
+
+#define UT 0.2
+#define BREATH 0.02
+#define V 0.5
+
+BusIn joy(p15,p12,p13,p16);
+C12832 lcd(p5,p7,p6,p8,p11);
+MMA7660 MMA(p28,p27);
+LM75B sensor(p28,p27);
+PwmOut spkr(p26);
+
+void MSSRSMDR()
+{
+    spkr.period(DO); spkr=V;   wait(0.5*UT-BREATH); 
+                     spkr=0.0; wait(BREATH);
+    spkr.period(RE); spkr=V;   wait(0.5*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(MI); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(SO); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(SO); spkr=V;   wait(1.5*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(LA); spkr=V;   wait(0.5*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(SO); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(MI); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(DO); spkr=V;   wait(1.5*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(RE); spkr=V;   wait(0.5*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr=0.0;
+}
+
+void MMRDR()
+{
+    spkr.period(MI); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(MI); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(RE); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(DO); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(RE); spkr=V;   wait(3.0*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr=0.0;
+}
+
+void MMRRD()
+{
+    spkr.period(MI); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(MI); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(RE); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(RE); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(DO); spkr=V;   wait(4.0*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr=0.0;
+}
+
+void FFLLSMDR()
+{
+    spkr.period(FA); spkr=V;   wait(2.0*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(FA); spkr=V;   wait(2.0*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(LA); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(LA); spkr=V;   wait(3.0*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(SO); spkr=V;   wait(2.0*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(MI); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(DO); spkr=V;   wait(UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr.period(RE); spkr=V;   wait(3.0*UT-BREATH);
+                     spkr=0.0; wait(BREATH);
+    spkr=0.0;
+}
+
+void sing()
+{
+    MSSRSMDR();
+    MMRDR();
+    MSSRSMDR();
+    MMRRD();
+    FFLLSMDR();
+    MSSRSMDR();
+    MMRRD();
+}
+
+void temp(int i)
+{
+    if(i>=0)
+    {
+        i=i%100;
+        morse(i/10);
+        morse(i%10);
+    }
+}
+
+int main()
+{
+    float x,y,z;
+    while(1)
+    {
+        x=MMA.x();
+        y=MMA.y();
+        z=MMA.z();
+        if(x*x+y*y+z*z>3.5) temp((int)sensor);
+        lcd.cls();
+        lcd.locate(0,0);
+        lcd.printf("Temp = %d\n",(int)sensor);
+        if(joy) sing();
+        wait(0.02);
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 9d7b581da110 main.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.h	Mon Feb 16 09:11:32 2015 +0000
@@ -0,0 +1,15 @@
+#ifndef __MAIN_H__
+#define __MAIN_H__
+
+#include "mbed.h"
+#include "C12832.h"
+#include "MMA7660.h"
+#include "LM75B.h"
+
+extern DigitalIn fire;
+extern C12832 lcd;
+extern MMA7660 MMA;
+extern LM75B sensor;
+extern PwmOut spkr;
+
+#endif
\ No newline at end of file
diff -r 000000000000 -r 9d7b581da110 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Feb 16 09:11:32 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc
\ No newline at end of file
diff -r 000000000000 -r 9d7b581da110 morse.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/morse.cpp	Mon Feb 16 09:11:32 2015 +0000
@@ -0,0 +1,158 @@
+#include "main.h"
+#include "morse.h"
+
+#define M 0.1
+#define V 0.5
+#define LA 0.002272727
+
+extern PwmOut spkr;
+
+void to()
+{
+    spkr.period(LA);
+    spkr=V;
+    wait(M);
+    spkr=0.0;
+    wait(M);
+}
+
+void tsu()
+{
+    spkr.period(LA);
+    spkr=V;
+    wait(3.0*M);
+    spkr=0.0;
+    wait(M);
+}
+
+void one()
+{
+    to();
+    wait(2.0*M);
+}
+
+void two()
+{
+    to();
+    to();
+    wait(2.0*M);
+}
+
+void three()
+{
+    to();
+    to();
+    to();
+    wait(2.0*M);
+}
+
+void four()
+{
+    to();
+    to();
+    to();
+    to();
+    wait(2.0*M);
+}
+
+void five()
+{
+    to();
+    to();
+    to();
+    to();
+    to();
+    wait(2.0*M);
+}
+
+void six()
+{
+    tsu();
+    wait(2.0*M);
+}
+
+void seven()
+{
+    tsu();
+    tsu();
+    wait(2.0*M);
+}
+
+void eight()
+{
+    tsu();
+    tsu();
+    tsu();
+    wait(2.0*M);
+}
+
+void nine()
+{
+    tsu();
+    tsu();
+    tsu();
+    tsu();
+    wait(2.0*M);
+}
+
+void zero()
+{
+    tsu();
+    tsu();
+    tsu();
+    tsu();
+    tsu();
+    wait(2.0*M);
+}
+
+void period()
+{
+    to();
+    tsu();
+    to();
+    tsu();
+    to();
+    tsu();
+    wait(6.0*M);
+}
+
+void morse(int i)
+{
+    if(i>=0) i=i%10;
+    switch(i%10)
+    {
+        case 1:
+            one();
+            break;
+        case 2:
+            two();
+            break;
+        case 3:
+            three();
+            break;
+        case 4:
+            four();
+            break;
+        case 5:
+            five();
+            break;
+        case 6:
+            six();
+            break;
+        case 7:
+            seven();
+            break;
+        case 8:
+            eight();
+            break;
+        case 9:
+            nine();
+            break;
+        case 0:
+            zero();
+            break;
+        default:
+            period();
+            break;
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 9d7b581da110 morse.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/morse.h	Mon Feb 16 09:11:32 2015 +0000
@@ -0,0 +1,19 @@
+#ifndef __MORSE_H__
+#define __MORSE_H__
+
+void to();
+void tsu();
+void one();
+void two();
+void three();
+void four();
+void five();
+void six();
+void seven();
+void eight();
+void nine();
+void zero();
+void period();
+void morse(int i);
+
+#endif
\ No newline at end of file