Don't ad-block us - support your favorite websites. We have safe, unobstrusive, robotics related ads that you actually want to see - see here for more.

0 Members and 1 Guest are viewing this topic.

#include "SoR_Utils.h" //Include the SoR_Utils header that came with the $50 robot code//21000 cycles is about 1 secondint x = 0; //Create an integer with the value of '0'int main(void) { DDRB = 0xFF; // Set all B ports to outputs DDRC = 0x00; // Set all C ports to intputs DDRD = 0xFF; // Set all D ports to outputs //PORT ID 0b76543210 PORTB = 0b00000000; // Set all B ports low PORTC = 0x00; // Set all C ports low PORTD = 0b00010000; // Set PD4 high and the other D ports to low while(1) // Basically just makes it loop forever - WARNING! BAD CODING STYLE! DONT DO IT! USE INTEGERS(0 or 1) OR BOOLEANS(TRUE or FALSE! { while(x < 100) //While x is less than 100(which it is because its 0 to start off with) { PORTB = 0b00000001; //Set PB0 high so the current in both directions cancel each other out(no flow) PORTD = 0b00000000; //Set all PD ports low [The LED from the $50 schematic is on a PD(PD4 to be exact)] delay_cycles(x*2); //Wait as many cycles as x*2 is equal to (starts off at 200 cycles, then 198, then 196, etc, etc) PORTB = 0b00000000; //Set all PB ports low so the current flows into them PORTD = 0b00010000; //Set PD4 high so the current cannot get into it x++; //take x and then increment(add 1) it } while(x > 0) //x should now be equal to 100 which is greater than 0 { PORTB = 0b00000001; //Set PB0 high so current cant flow through PORTD = 0b00000000; //Set all PD ports low so current can flow delay_cycles(x); //Delay as many cycles as x represents (starting at 100 going down to 0) PORTB = 0b00000000; //Set all PB ports to low so current can flow PORTD = 0b00010000; //Set PD4 high so current cannot flow x--; } while(x < 100) { PORTB = 0b00000001; PORTD = 0b00000000; delay_cycles(x*2); PORTB = 0b00000000; PORTD = 0b00010000; x++; } x = 200; //I did this instead of x=25 and x > 0 because the number 'x' represents the frequency being emitted not the amount of cycles to be delayed(in this case 25 cycles are delayed). The difference between x and the desired stop point determines the amount of cycles delayed while(x > 175) { PORTB = 0b00000001; PORTD = 0b00000000; delay_cycles(x); PORTB = 0b00000000; PORTD = 0b00010000; x--; } x=0; // I had to do this because 'x' is equal to 175 now which would throw off the first 3 while loops in the code } }

but first im working on writing a utility to make it easier and more efficient to write songs using a piezo