Hi everyone,
This is the first code I have written (hopefully my ruggeduino will come in tomorrow). ![]()
The plan:
POT input on pin 0 to control PWM %
PWM output on pin 9 @ fixed 50Hz
Here is the thread for my project.
http://arduino.cc/forum/index.php/topic,69965.0.html
I am looking for some help with Timer1 functions.
Just recently replaced analogWrite() with setPwmDuty()
Now when I verify code I return this error.
pwm_solenoid.cpp: In function 'void loop()':
pwm_solenoid:38: error: 'setPwmDuty' was not declared in this scope
Here is the code as I have it right now.
#include <TimerOne.h>
// these constant variables store the pin numbers
const int solenoidPin = 9; // Solenoid connected to digital pin 9
const int knobPin = 0; // potentiometer wiper (middle terminal) connected to analog pin 0
// outside terminals to ground and +5V
int knobValue, pwmValue; // these variables store the values for the knob and PWM level
void setup() {
Serial.begin(9600); // initialize the serial port
Timer1.initialize(20000); // Set a timer of 50Hz
}
void loop() {
knobValue = analogRead(knobPin); // read the value from the input
pwmValue = map(knobValue, 0, 1023, 0, 254); // remap the values from 10 bit input to 8 bit output
setPwmDuty(solenoidPin, pwmValue); // use the input value to control the solenoid
Serial.println(pwmValue); // print the input value to the serial port for debugging
}
Could someone give me a hand with what I have right and what needs to be changed.
Also is Timer1.initialize() set up correctly for operation @ 50Hz?
Thanks