Created
December 15, 2018 03:32
-
-
Save derglow/f926ab8df2d38c2f61ee1bde8bf1e1e3 to your computer and use it in GitHub Desktop.
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
//I wrote freq a lot below but really meant period. | |
uint16_t freqList[] = {5759,1920,960,576,384,274,206,160,128,105,87,74,63,55,48,42,38,34,30,27,25,23,21,19,18,16,15,14,13,12,12,11,10,10,9,9,8,8,7,7,7,6,6,6,6,5,5,5,5,5}; | |
uint16_t lastFreqUpdate = 0; | |
uint16_t currentMSTimer = 0; | |
uint16_t updateTime = 100; | |
uint16_t currentIndex = 1; | |
uint16_t maxIndex = 49; | |
uint16_t activeFreq = 0; | |
uint16_t indexDir = 1; | |
void setup() { | |
pinMode(13,OUTPUT); | |
lastFreqUpdate=millis(); | |
} | |
void loop() { | |
//one block of code needs to monitor for 100ms increments and update the current frequency | |
currentMSTimer = millis(); | |
if(currentMSTimer - lastFreqUpdate > updateTime){ | |
if(indexDir==1 && currentIndex < maxIndex){ | |
currentIndex++; | |
} | |
if(indexDir==0 && currentIndex > 0){ | |
currentIndex--; | |
} | |
if(currentIndex==0){indexDir=1;} | |
if(currentIndex==maxIndex){indexDir=0;} | |
activeFreq = freqList[currentIndex]; | |
lastFreqUpdate = currentMSTimer; | |
} | |
// second block of code needs to toggle the digital output at the proper frequency | |
if((2*(currentMSTimer%activeFreq))>activeFreq){digitalWrite(13,HIGH);} | |
else{digitalWrite(13,LOW);} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment