conehead NZ
/
Ass2
Beats and Bars - Assignment 2
main.cpp@0:690b6f38fac1, 2017-10-01 (annotated)
- Committer:
- conehead
- Date:
- Sun Oct 01 07:00:36 2017 +0000
- Revision:
- 0:690b6f38fac1
V1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
conehead | 0:690b6f38fac1 | 1 | // Damon Hill - 14234098 - 159.270 |
conehead | 0:690b6f38fac1 | 2 | // Assignment 2 - Beats and Bars |
conehead | 0:690b6f38fac1 | 3 | #include "mbed.h" |
conehead | 0:690b6f38fac1 | 4 | |
conehead | 0:690b6f38fac1 | 5 | PwmOut yellowLED(LED1); // declare LED outputs |
conehead | 0:690b6f38fac1 | 6 | PwmOut blueLED(PA_7); |
conehead | 0:690b6f38fac1 | 7 | |
conehead | 0:690b6f38fac1 | 8 | unsigned int beatA,beatB; // declare beats and PWM period |
conehead | 0:690b6f38fac1 | 9 | float periodA, periodB; |
conehead | 0:690b6f38fac1 | 10 | |
conehead | 0:690b6f38fac1 | 11 | int main() |
conehead | 0:690b6f38fac1 | 12 | { |
conehead | 0:690b6f38fac1 | 13 | beatA = 3; // set LED beats |
conehead | 0:690b6f38fac1 | 14 | beatB = 4; |
conehead | 0:690b6f38fac1 | 15 | periodA = 12/beatA; // 12/beat to get time for one beat in a 12 second bar |
conehead | 0:690b6f38fac1 | 16 | periodB = 12/beatB; |
conehead | 0:690b6f38fac1 | 17 | |
conehead | 0:690b6f38fac1 | 18 | yellowLED = 1; //turn LEDs high at start of bar |
conehead | 0:690b6f38fac1 | 19 | blueLED = 1; |
conehead | 0:690b6f38fac1 | 20 | |
conehead | 0:690b6f38fac1 | 21 | yellowLED.period(periodA); //set period |
conehead | 0:690b6f38fac1 | 22 | blueLED.period(periodB); |
conehead | 0:690b6f38fac1 | 23 | yellowLED.pulsewidth(1); //pulse led for 1 second |
conehead | 0:690b6f38fac1 | 24 | blueLED.pulsewidth(1); |
conehead | 0:690b6f38fac1 | 25 | |
conehead | 0:690b6f38fac1 | 26 | while (1); |
conehead | 0:690b6f38fac1 | 27 | } |