Arduino code from video:
bool tog = false; //variable to toggle digital output
int cDiv = 1; //varible to hold clock divider
int count = 0; //variable to track when to switch clock freq
void setup() {
PM->CPUSEL.reg = PM_CPUSEL_CPUDIV(1); //Sets CPU frequency: power management struct, CPUSEL union, register variable
pinMode(3, OUTPUT); //set D3 to output
}
void loop() {
if(tog) tog = false; //if tog is true turn it false
else tog =true;
digitalWrite(3,tog); //set digital output
count++;
if(count > 6) { //check if it is time to change clock frequency
if(cDiv == 1) cDiv = 4;
else cDiv = 1;
PM->CPUSEL.reg = PM_CPUSEL_CPUDIV(cDiv); //PM_CPUSEL_CPUDIV_DIV4_Val
count = 0;
}
}
No comments:
Post a Comment