eLab Team / Mbed 2 deprecated LaLaBox

Dependencies:   mbed CREALIB

Committer:
garphil
Date:
Fri Jun 24 15:00:15 2016 +0000
Revision:
5:f62e799558c3
Parent:
4:d452a7e3461a
Child:
6:2f4867594333
Added management of button (when no driver for debug). ; + tested on board

Who changed what in which revision?

UserRevisionLine numberNew contents of line
garphil 1:ab4c9a0a5374 1 #include "LaLaBox.h"
garphil 1:ab4c9a0a5374 2
garphil 1:ab4c9a0a5374 3 // ---------------- Local global variables --------------
garphil 1:ab4c9a0a5374 4
garphil 1:ab4c9a0a5374 5 // --- Sound ---
garphil 1:ab4c9a0a5374 6 char *song_happy_birthday = "Happy Birthday Song:d=4,o=5,b=125:16c,32p,32c,32p,8d,32p,8c,32p,8f,32p,e,16p,16c,32p,32c,32p,8d,32p,8c,32p,8g,32p,f,8p,16c,32p,32c,32p,8c6,32p,8a,32p,8f,32p,8e,32p,8d,32p,16a#,32p,32a#,32p,8a,32p,8f,32p,8g,32p,f";
garphil 1:ab4c9a0a5374 7 char *song_greensleaves = "Greensleaves:d=4,o=5,b=140:g,2a#,c6,d.6,8d#6,d6,2c6,a,f.,8g,a,2a#,g,g.,8f,g,2a,f,2d,g,2a#,c6,d.6,8e6,d6,2c6,a,f.,8g,a,a#.,8a,g,f#.,8e,f#,2g";
garphil 1:ab4c9a0a5374 8 char *song_lightmyfire = "LightMyFire:d=4,o=5,b=140:8b,16g,16a,8b,8d6,8c6,8b,8a,8g,8a,16f,16a,8c6,8f6,16d6,16c6,16a#,16g,8g#,8g,8g#,16g,16a,8b,8c#6,16b,16a,16g,16f,8e,8f,1a,a";
garphil 1:ab4c9a0a5374 9 char *song_xfile = "Xfiles:d=4,o=5,b=140:e,b,a,b,d6,2b.";
garphil 1:ab4c9a0a5374 10 char *song_christmas ="Christmas:d=4,o=5,b=100:f#,g#,2a#,2a#,d#.,8f,f,f,2f#,2d#,2f#.6,f#,#g,8g#,g#,8a#,b,8c#,c#,2c#,8d#,8f.,8f#.,8f.,d#,f,2f#.,a#,8b.,8b.,8b.,d#,f,2c#.,a#,8b.,8b.,8b.,d#,f,f#,p,g#,g#,g#,8g#,8a#,8g#,f#.,g#,a#,p,c,c,c,8c,8c#,8c,a#.,c,c#,a#,b,a#,a,a#,b,c,";
garphil 1:ab4c9a0a5374 11
garphil 2:050f12806bc5 12 // ---------------- PIN DEFINITIONS ---------------------
garphil 2:050f12806bc5 13 DigitalOut myled(LED1); // Blinking LED
garphil 5:f62e799558c3 14 InterruptIn myButton(USER_BUTTON);
garphil 2:050f12806bc5 15
garphil 2:050f12806bc5 16 // --- Define the Foor PINs used for Motor drive -----
garphil 4:d452a7e3461a 17 Motor motorBox(PA_9, PC_7, PB_6, PA_7);
garphil 3:50e030d90648 18 // Motor motorDancer(PA_9, PC_7, PB_6, PA_7)
garphil 2:050f12806bc5 19
garphil 1:ab4c9a0a5374 20 // --- Define PC_8 as the output of PWM use for Tones -----
garphil 1:ab4c9a0a5374 21 Buzzer buzzer(PC_8);
garphil 0:30cb0f6dad87 22
garphil 1:ab4c9a0a5374 23 Music* pMusic=0; //the song
garphil 1:ab4c9a0a5374 24 Note la("A#4",50); //the sound
garphil 1:ab4c9a0a5374 25
garphil 5:f62e799558c3 26 // init
garphil 5:f62e799558c3 27 bool state = false;
garphil 2:050f12806bc5 28
garphil 1:ab4c9a0a5374 29 void help() // Display list of Commands
garphil 1:ab4c9a0a5374 30 {
garphil 1:ab4c9a0a5374 31 DEBUG("List of commands:\n\r");
garphil 1:ab4c9a0a5374 32 DEBUG(" h --> Help, display list of cammands\n\r");
garphil 1:ab4c9a0a5374 33 DEBUG(" z --> Go to motor zero\n\r");
garphil 1:ab4c9a0a5374 34 DEBUG(" k --> Calibrate motor\n\r");
garphil 1:ab4c9a0a5374 35 DEBUG(" n dddd --> define Number of coils (default=100)\n\r");
garphil 1:ab4c9a0a5374 36 DEBUG(" c --> define Clockwise (default)\n\r");
garphil 1:ab4c9a0a5374 37 DEBUG(" a --> define Anti-clockwise\n\r");
garphil 1:ab4c9a0a5374 38 DEBUG(" m --> Memorise configuration\n\r");
garphil 1:ab4c9a0a5374 39 DEBUG(" l --> List current configuration\n\r");
garphil 1:ab4c9a0a5374 40 DEBUG(" w --> start Wiring the coils\n\r");
garphil 1:ab4c9a0a5374 41 DEBUG(" p --> Pause wiring\n\r");
garphil 1:ab4c9a0a5374 42 DEBUG(" r --> Resume wiring\n\r");
garphil 1:ab4c9a0a5374 43 DEBUG(" s --> Stop (abort) wiring\n\r");
garphil 1:ab4c9a0a5374 44 DEBUG(" [space] --> print remaining Motor steps\n\r");
garphil 1:ab4c9a0a5374 45 }
garphil 1:ab4c9a0a5374 46
garphil 5:f62e799558c3 47 void pressed() {
garphil 5:f62e799558c3 48 if(state) {
garphil 5:f62e799558c3 49 motorBox.RunDegrees(DIRECTION_CLOCKWISE, (float)90.0);
garphil 5:f62e799558c3 50 } else {
garphil 5:f62e799558c3 51 motorBox.RunDegrees(DIRECTION_COUNTERCLOCKWISE, (float)360.0);
garphil 5:f62e799558c3 52 }
garphil 5:f62e799558c3 53 state = ! state;
garphil 5:f62e799558c3 54 }
garphil 5:f62e799558c3 55
garphil 0:30cb0f6dad87 56 int main() {
garphil 1:ab4c9a0a5374 57 myled = 1; // To see something is alive
garphil 1:ab4c9a0a5374 58 DEBUG("\n\n\r");
garphil 1:ab4c9a0a5374 59 DEBUG("------------------------------------------\n\r");
garphil 4:d452a7e3461a 60 DEBUG("----- LaLaBox (fbd38) version 1.0 ----\n\r");
garphil 1:ab4c9a0a5374 61 DEBUG("------------------------------------------\n\r");
garphil 1:ab4c9a0a5374 62 help();
garphil 1:ab4c9a0a5374 63 DEBUG("------------------------------------------\n\r");
garphil 5:f62e799558c3 64
garphil 5:f62e799558c3 65 myButton.fall(&pressed);
garphil 5:f62e799558c3 66
garphil 1:ab4c9a0a5374 67 wait(5); // Some delay
garphil 1:ab4c9a0a5374 68 myled = 0; // Real stuff starts here
garphil 5:f62e799558c3 69
garphil 5:f62e799558c3 70
garphil 5:f62e799558c3 71 motorBox.SetDirection(DIRECTION_CLOCKWISE);
garphil 5:f62e799558c3 72 while(1) {
garphil 1:ab4c9a0a5374 73 char command; // Command to execute
garphil 5:f62e799558c3 74 DEBUG(">> ");
garphil 1:ab4c9a0a5374 75 command = pc_uart.getc();
garphil 1:ab4c9a0a5374 76 DEBUG("%c", command);
garphil 5:f62e799558c3 77
garphil 1:ab4c9a0a5374 78 switch (command) {
garphil 1:ab4c9a0a5374 79 case 'h': help(); break;
garphil 4:d452a7e3461a 80 case 'z': motorBox.SetCommand(MOTOR_zero); break;
garphil 4:d452a7e3461a 81 case 'k': motorBox.TestMotor(); break;
garphil 4:d452a7e3461a 82 case 'c':
garphil 4:d452a7e3461a 83 DEBUG(" -- Direction CLOCKWISE --\n\r");
garphil 4:d452a7e3461a 84 motorBox.SetDirection(DIRECTION_CLOCKWISE);
garphil 1:ab4c9a0a5374 85 break;
garphil 4:d452a7e3461a 86 case 'a':
garphil 4:d452a7e3461a 87 DEBUG(" -- Direction COUNTER CLOCKWISE --\n\r");
garphil 4:d452a7e3461a 88 motorBox.SetDirection(DIRECTION_COUNTERCLOCKWISE);
garphil 4:d452a7e3461a 89 break;
garphil 4:d452a7e3461a 90 case 'w': DEBUG(" -- Starting --\n\r"); motorBox.SetCommand(MOTOR_start); break;
garphil 4:d452a7e3461a 91 case 'p': DEBUG(" -- Pause --\n\r"); motorBox.SetCommand(MOTOR_pause); break;
garphil 4:d452a7e3461a 92 case 'r': DEBUG(" -- Re-Start --\n\r"); motorBox.SetCommand(MOTOR_restart); break;
garphil 4:d452a7e3461a 93 case 's': DEBUG(" -- Stop --\n\r"); motorBox.SetCommand(MOTOR_stop); break;
garphil 1:ab4c9a0a5374 94 default : DEBUG("invalid command; use: 'h' for help()");
garphil 1:ab4c9a0a5374 95 }
garphil 0:30cb0f6dad87 96 }
garphil 1:ab4c9a0a5374 97 }