Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <avr/wdt.h>
- short int potPos(0);
- // This turns off the magic stuff
- const bool regActive = true;
- void setup()
- {
- pinMode(0,OUTPUT);
- pinMode(1,OUTPUT);
- /*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. */
- if(regActive)
- {
- // This was taken from another
- TCCR0A = 2<<COM0A0 | 3<<COM0B0 | 3<<WGM00;
- TCCR0B = 0<<WGM02 | 1<<CS00;
- GTCCR = 1<<PWM1B | 2<<COM1B0;
- TCCR1 = 0<<PWM1A | 0<<COM1A0 | 1<<CS10;
- }
- }
- void loop()
- {
- // Gets the Duty Cycle from the POT
- potPos = map(analogRead(A3),0,1023,0,255);
- // Makes the signal
- analogWrite(0,potPos);
- analogWrite(1,0);
- analogWrite(1,potPos);
- analogWrite(0,0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement