Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Declare port where read potentiometer value
  2. #define inpot A0
  3. char key; //Declare variable to store key
  4. int period; //T o periodo dell'onda QUADRATA
  5. float perc_dc; //Percentuale duty cycle
  6. void dc(); //Declare DC generator as void
  7.  
  8. void setup(){
  9.     Serial.begin(9600);
  10.     pinMode(AO, INPUT);
  11.     DDRD= DDRD | B00111100; //Pin 2-5 OUTPUT
  12.     period= 100;
  13. }
  14.  
  15. void loop(){
  16.     key= Serial.Read(); //Reading keyboard char on Serial
  17.     perc_dc= AnalogRead(AO)/1023 //Convertion potentiometer in duty cycle
  18.     if (key=='c') PORTD= B00111100; //PINs 2-5 ON
  19.     else if (key=='a') dc(); //Use DC generator
  20.     else PORTD= B00000000; //All PINs OFF
  21. }
  22.  
  23. void dc(){
  24.     PORTD= B00111100; //Set all led ON
  25.     delaymicroseconds(period/perc_dc); //Waiting first part of wave
  26.     PORTD= B00000000; //Set all led OF
  27.     delaymicroseconds(period/(1-perc_dc)); //Waiting second part of ware
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement