Advertisement
Guest User

Untitled

a guest
Sep 26th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <avr/wdt.h>
  2.  
  3. short int potPos(0);
  4. // This turns off the magic stuff
  5. const bool regActive = true;
  6.  
  7. void setup()
  8. {
  9.  
  10. pinMode(0,OUTPUT);
  11. pinMode(1,OUTPUT);
  12. /*This is the register stuff that allows analogWrite in theory to run faster. It works on PB0 however it does not work whatsoever on PB1. These little hacks where taken from a different project. */
  13. if(regActive)
  14. {
  15. // This was taken from another
  16. TCCR0A = 2<<COM0A0 | 3<<COM0B0 | 3<<WGM00;
  17. TCCR0B = 0<<WGM02 | 1<<CS00;
  18. GTCCR = 1<<PWM1B | 2<<COM1B0;
  19. TCCR1 = 0<<PWM1A | 0<<COM1A0 | 1<<CS10;
  20. }
  21. }
  22.  
  23. void loop()
  24. {
  25. // Gets the Duty Cycle from the POT
  26. potPos = map(analogRead(A3),0,1023,0,255);
  27. // Makes the signal
  28. analogWrite(0,potPos);
  29. analogWrite(1,0);
  30. analogWrite(1,potPos);
  31. analogWrite(0,0);
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement