Created
March 2, 2012 00:28
-
-
Save eggie5/1954259 to your computer and use it in GitHub Desktop.
putting this here for posterity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <hidef.h> /* common defines and macros */ | |
#include "derivative.h" /* derivative-specific definitions */ | |
#define SL 16 //sequence length | |
//word is unsigned int | |
void delay(word d); | |
word delayTime=2000/SL; //125 ms | |
void delay(word d) | |
{ | |
int constant=350; | |
int i; | |
while(d>0) | |
{ | |
i = constant; | |
while(i>0) | |
i--; | |
d--; | |
} | |
} | |
void readButtons() | |
{ | |
word delta=500/SL; //32.12 ms | |
if(PTM_PTM4 == 0) | |
{ | |
delay(10); | |
while(PTM_PTM4==0) { ; } | |
delay(10); | |
if(delayTime>=delta) | |
delayTime-=delta; | |
else | |
delayTime=0; | |
} | |
else if(PTM_PTM5==0) | |
{ | |
delay(10); | |
while (PTM_PTM5==0) | |
{ ; } | |
delay(10); | |
delayTime+=delta; | |
} | |
} | |
void main(void) | |
{ | |
int i; | |
byte patterns[]={0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF,0x7F,0x1F,0x0F,0x07,0x03,0x01,0x00}; | |
DDRA=0xFF; // make all the bits of port A outputs | |
//use the folowing to calibrate the delay functions | |
//PORTA=0xFF; | |
//delay2(10000); | |
//PORTA=0x00; | |
while(1) | |
{ | |
for(i=0; i<SL; i++) | |
{ | |
PORTA=patterns[i]; | |
delay(delayTime); | |
readButtons(); | |
}//end for | |
}//end while | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment