Blah. Read revision notes

Dependencies:   Motor Servo mbed

Committer:
christianjaunich
Date:
Mon Oct 20 21:38:52 2014 +0000
Revision:
0:038660e2c0c5
Can you guys look this over and dig around the internet and see if you can find any resources that might allow for frequencies to be played without messing with the PWM period?

Who changed what in which revision?

UserRevisionLine numberNew contents of line
christianjaunich 0:038660e2c0c5 1 #include "mbed.h"
christianjaunich 0:038660e2c0c5 2 #include "Motor.h"
christianjaunich 0:038660e2c0c5 3 #include "Servo.h"
christianjaunich 0:038660e2c0c5 4
christianjaunich 0:038660e2c0c5 5 PwmOut speaker(p23); //Speaker Control //*** I changed this to 25.
christianjaunich 0:038660e2c0c5 6 BusOut myled(p5,p6,p7,p8,p11); //Data bus for LEDs
christianjaunich 0:038660e2c0c5 7 DigitalIn switch2(p16); //Switch 2
christianjaunich 0:038660e2c0c5 8 DigitalIn switch3(p17); //Switch 3
christianjaunich 0:038660e2c0c5 9 DigitalIn switch4(p18); //Switch 4
christianjaunich 0:038660e2c0c5 10 DigitalIn switch5(p19); //Switch 5
christianjaunich 0:038660e2c0c5 11 Motor motor1(p26,p29,p30); /// *** motor only seems to work on these pins. JP
christianjaunich 0:038660e2c0c5 12 Servo servo1(p21); //Flag Servo
christianjaunich 0:038660e2c0c5 13 Servo servo2(p22); //Salute Servo
christianjaunich 0:038660e2c0c5 14 int random;
christianjaunich 0:038660e2c0c5 15
christianjaunich 0:038660e2c0c5 16 int main()
christianjaunich 0:038660e2c0c5 17 {
christianjaunich 0:038660e2c0c5 18 float servopos1=0.0; //Initializing servo position for servo1
christianjaunich 0:038660e2c0c5 19 float servopos2=0.0; //Initializing servo position for servo2
christianjaunich 0:038660e2c0c5 20 float motorspeed = 1; //Initializing motor speed
christianjaunich 0:038660e2c0c5 21 int light=1; //Initializing value to be passed into LED bus
christianjaunich 0:038660e2c0c5 22 float volume;
christianjaunich 0:038660e2c0c5 23
christianjaunich 0:038660e2c0c5 24 while(1) {
christianjaunich 0:038660e2c0c5 25 if((switch2==0)&&(switch3==0)&&(switch4)==0&&(switch5==0)) { //Turn off
christianjaunich 0:038660e2c0c5 26 servopos1=0.0;
christianjaunich 0:038660e2c0c5 27 servopos2=0.0;
christianjaunich 0:038660e2c0c5 28 servo1=servopos1;
christianjaunich 0:038660e2c0c5 29 servo2=servopos2;
christianjaunich 0:038660e2c0c5 30 motor1.speed(0);
christianjaunich 0:038660e2c0c5 31 speaker=0.0;
christianjaunich 0:038660e2c0c5 32 light=0;
christianjaunich 0:038660e2c0c5 33 myled=light;
christianjaunich 0:038660e2c0c5 34 } else if((switch2==1)&&(switch3==0)&&(switch4==0)&&(switch5==0)) { //Flag raising, sounds, salute, lights
christianjaunich 0:038660e2c0c5 35 light=1;
christianjaunich 0:038660e2c0c5 36 speaker=0.25;
christianjaunich 0:038660e2c0c5 37 wait(.5);
christianjaunich 0:038660e2c0c5 38 speaker=.75;
christianjaunich 0:038660e2c0c5 39 wait(.5);
christianjaunich 0:038660e2c0c5 40 servopos1=.40; //Flag rotation
christianjaunich 0:038660e2c0c5 41 servo1=servopos1;
christianjaunich 0:038660e2c0c5 42 servo2=.5;
christianjaunich 0:038660e2c0c5 43 if(servo1.read()==.40) {
christianjaunich 0:038660e2c0c5 44 servo2=1.0;
christianjaunich 0:038660e2c0c5 45 }
christianjaunich 0:038660e2c0c5 46 while(light<32) { //Incrementing lights
christianjaunich 0:038660e2c0c5 47 myled=light;
christianjaunich 0:038660e2c0c5 48 light=(light*2)+1;
christianjaunich 0:038660e2c0c5 49 wait(1.0/9.0);
christianjaunich 0:038660e2c0c5 50 }
christianjaunich 0:038660e2c0c5 51 } else if((switch2==0)&&(switch3==1)&&(switch4==0)&&(switch5==0)) { //Fan, lights, sounds
christianjaunich 0:038660e2c0c5 52 motor1.speed(motorspeed); //Turns on Fan
christianjaunich 0:038660e2c0c5 53 volume=25;
christianjaunich 0:038660e2c0c5 54 for(light=1; light<16; light++) {
christianjaunich 0:038660e2c0c5 55 myled=light;
christianjaunich 0:038660e2c0c5 56 wait(.3);
christianjaunich 0:038660e2c0c5 57 if((switch2==0)&&(switch3==0)&&(switch4==0)&&(switch5==0)) {
christianjaunich 0:038660e2c0c5 58 break;
christianjaunich 0:038660e2c0c5 59 }
christianjaunich 0:038660e2c0c5 60 }
christianjaunich 0:038660e2c0c5 61 while(volume>0) { //Decreasing and Increasing volume in sequence
christianjaunich 0:038660e2c0c5 62 volume=1;
christianjaunich 0:038660e2c0c5 63 speaker = float(volume)/50.0;
christianjaunich 0:038660e2c0c5 64 wait(.5);
christianjaunich 0:038660e2c0c5 65 wait(.5);
christianjaunich 0:038660e2c0c5 66 if(volume>0) {
christianjaunich 0:038660e2c0c5 67 volume-=2;
christianjaunich 0:038660e2c0c5 68 } else if(volume<0) {
christianjaunich 0:038660e2c0c5 69 volume+=2;
christianjaunich 0:038660e2c0c5 70 }
christianjaunich 0:038660e2c0c5 71
christianjaunich 0:038660e2c0c5 72 }
christianjaunich 0:038660e2c0c5 73 } else if((switch2==0)&&(switch3==0)&&(switch4==1)&&(switch5==0)) { //Siren, Building Lights
christianjaunich 0:038660e2c0c5 74 // two tone police siren effect - two periods or two frequencies
christianjaunich 0:038660e2c0c5 75 speaker=0.25;
christianjaunich 0:038660e2c0c5 76 wait(.5);
christianjaunich 0:038660e2c0c5 77 speaker=.5;
christianjaunich 0:038660e2c0c5 78 wait(.5);
christianjaunich 0:038660e2c0c5 79 myled=light; //Increasing Lights
christianjaunich 0:038660e2c0c5 80 light=(light*2)+1;
christianjaunich 0:038660e2c0c5 81 wait(.5);
christianjaunich 0:038660e2c0c5 82 if(light>=32) {
christianjaunich 0:038660e2c0c5 83 light=1;
christianjaunich 0:038660e2c0c5 84 }
christianjaunich 0:038660e2c0c5 85 } else if((switch2==0)&&(switch3==0)&&(switch4==0)&&(switch5==1)) { //Salute and cut salute
christianjaunich 0:038660e2c0c5 86 if(servopos2==0.0) {
christianjaunich 0:038660e2c0c5 87 servopos2=.5;
christianjaunich 0:038660e2c0c5 88 servo2=servopos2;
christianjaunich 0:038660e2c0c5 89 }
christianjaunich 0:038660e2c0c5 90 } else if(servopos2==.5) {
christianjaunich 0:038660e2c0c5 91 servopos2=0;
christianjaunich 0:038660e2c0c5 92 { //Cut salute
christianjaunich 0:038660e2c0c5 93 servo2=servopos2;
christianjaunich 0:038660e2c0c5 94 }
christianjaunich 0:038660e2c0c5 95 }
christianjaunich 0:038660e2c0c5 96 }
christianjaunich 0:038660e2c0c5 97 }
christianjaunich 0:038660e2c0c5 98
christianjaunich 0:038660e2c0c5 99
christianjaunich 0:038660e2c0c5 100
christianjaunich 0:038660e2c0c5 101
christianjaunich 0:038660e2c0c5 102
christianjaunich 0:038660e2c0c5 103