i've got my nano to pulse and can adjust the on time with a potentiometer and the off time with onother one, all i want is 1 more pot to adjust my frequentie is that possible, here is how far i am
int ledPin = 9; // LED connected to digital pin 9
int analogPin = 3; // potentiometer connected to analog pin 3
int val = 0; // variable to store the read value
int analogPin2 = 2; // potentiometer connected to analog pin 3
int val2 = 0; // variable to store the read value
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // sets the pin as output
TCCR2B = TCCR2B & 0b11111000 | 0x01;
}
void loop()
{
val = analogRead(analogPin); // read the input pin
val2 = analogRead(analogPin2); // read the input pin
digitalWrite(9, HIGH);
delayMicroseconds(val); // Approximately 10% duty cycle @ 1KHz
digitalWrite(9, LOW);
delayMicroseconds(val2);
}
whel it works like this but i don't think that's how is should be done
any idea's
int ledPin = 9; // LED connected to digital pin 9
int analogPin = 3; // potentiometer connected to analog pin 3
int val = 0; // variable to store the read value
int analogPin2 = 2; // potentiometer connected to analog pin 2
int val2 = 0; // variable to store the read value
int analogPin3 = 1; // potentiometer connected to analog pin 1
int val3 = 0; // variable to store the read value
void setup()
{
pinMode(ledPin, OUTPUT); // sets the pin as output
TCCR2B = TCCR2B & 0b11111000 | 0x01;
}
void loop()
{
val3 = analogRead(analogPin3);
val = analogRead(analogPin); // read the input pin
val2 = analogRead(analogPin2); // read the input pin
digitalWrite(9, HIGH);
delayMicroseconds(val + val3); // Approximately 10% duty cycle @ 1KHz
digitalWrite(9, LOW);
delayMicroseconds(val2 + val3);
}
Messing with the timer registers TCCR2B = TCCR2B & 0b11111000 | 0x01;
makes no sense to me, and I see no reason in your posted code for it. Suggest trying removal.
best,
Michael
Edit: P.S. analogRead and digitalWrite each take a fair number of processor cycles, so your 10% duty cycle is not going to be very accurate.