Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Declare port where read potentiometer value
- #define inpot A0
- char key; //Declare variable to store key
- int period; //T o periodo dell'onda QUADRATA
- float perc_dc; //Percentuale duty cycle
- void dc(); //Declare DC generator as void
- void setup(){
- Serial.begin(9600);
- pinMode(AO, INPUT);
- DDRD= DDRD | B00111100; //Pin 2-5 OUTPUT
- period= 100;
- }
- void loop(){
- key= Serial.Read(); //Reading keyboard char on Serial
- perc_dc= AnalogRead(AO)/1023 //Convertion potentiometer in duty cycle
- if (key=='c') PORTD= B00111100; //PINs 2-5 ON
- else if (key=='a') dc(); //Use DC generator
- else PORTD= B00000000; //All PINs OFF
- }
- void dc(){
- PORTD= B00111100; //Set all led ON
- delaymicroseconds(period/perc_dc); //Waiting first part of wave
- PORTD= B00000000; //Set all led OF
- delaymicroseconds(period/(1-perc_dc)); //Waiting second part of ware
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement