Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * LED_Flash.c
- *
- * Created: 12/26/2012 9:21:09 PM
- * Author: grist.carrigafoyl
- Simple program to emulate a heartbeat using LEDs.
- PWM output on PB0 (pin 5)
- Input for mode switching on PB3 (pin 2)
- */
- #define F_CPU 8000000UL // 8Mhz
- #include <avr/io.h>
- #include <avr/interrupt.h>
- #include <util/delay.h>
- // Prototypes
- int main();
- void fullOn();
- void heartBeat();
- void beatOne();
- void beatTwo();
- int main(void)
- {
- char button_state;
- // Set PortB to output, except our switch pin (PB3)
- DDRB = 0b11110111;
- // Turn on the pullup resistor
- PORTB = _BV(PB3);
- // Initialise PWM
- TCCR0A = 0b10000011; // Fast PWM 8 bit
- TCCR0B = 0b00000001; // No prescaler
- TCNT0 = 0; // Reset TCNT0
- while(1) {
- //fadeUpAndDown(5);
- //fullOn();
- button_state = ~PINB & _BV(PB3);
- if (button_state == 0) {
- heartBeat();
- } else {
- fullOn();
- }
- }
- }
- void fullOn()
- {
- int ms_delay_time = 250;
- OCR0A = 255;
- _delay_ms(ms_delay_time);
- }
- void heartBeat()
- { // Run through a single heartbeat
- // Numbers obtained from http://pastebin.com/FbjcsQM9
- int beatOneGap = 150; // ms
- int beatTwoGap = 546; // ms
- // Play it
- beatOne();
- _delay_ms(beatOneGap);
- beatTwo();
- _delay_ms(beatTwoGap);
- }
- void beatOne()
- { // Split these as having both data sets in the same function was hitting memory problems
- char dataOne[] = {
- 9, 18, 28, 37, 46, 48,
- 51, 55, 60, 64, 85, 107, 95, 83, 71, 102, 133, 163, 194, 224, 255, 255,
- 255, 255, 255, 255, 255, 255, 233, 211, 189, 150, 112, 74, 36, 41, 46, 51,
- 56, 71, 87, 102, 117, 133, 129, 126, 123, 120, 116, 113, 110, 107, 103, 100,
- 97, 92, 87, 82, 77, 71, 66, 61, 56, 51, 51, 51, 51, 51, 51, 48,
- 46, 43, 41, 38, 36, 33, 31, 28, 26, 24, 22, 19, 17, 15, 13, 13,
- 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 10, 6, 3, 0, 2,
- 4, 7, 9, 11, 13, 16, 18
- };
- for (int i=0;i<sizeof(dataOne);i++) {
- OCR0A = dataOne[i];
- _delay_ms(1);
- }
- }
- void beatTwo()
- { // Split these as having both data sets in the same function was hitting memory problems
- char dataTwo[] = {
- 13, 19, 26,
- 32, 38, 64, 89, 115, 143, 171, 199, 213, 227, 241, 255, 255, 255, 255, 255,
- 255, 255, 214, 173, 133, 92, 51, 49, 48, 47, 45, 43, 36, 28, 20, 54,
- 87, 120, 153, 166, 181, 194, 214, 235, 255, 255, 255, 255, 255, 255, 255, 217,
- 179, 140, 124, 108, 92, 77, 69, 61, 54, 46, 40, 33, 27, 20, 18, 13,
- 14, 12, 10, 8, 6, 4, 2, 0, 2, 4, 6, 8, 10, 12, 14, 16,
- 18, 20, 20, 20, 20, 19, 19, 19, 18, 18, 18, 18, 17, 17, 17, 16,
- 16, 16, 16, 15, 15, 15, 14, 14, 13, 13, 13, 12, 12, 11, 11, 11,
- 10, 10, 10, 9, 9, 9, 9, 8, 8, 8, 8, 7, 7, 7, 6, 6,
- 6, 6, 5, 5, 5, 5, 4, 4, 4, 3, 3, 3, 2, 2, 2, 2,
- 1, 1, 1
- };
- for (int i=0;i<sizeof(dataTwo);i++) {
- OCR0A = dataTwo[i];
- _delay_ms(1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement