I am trying to control a treadmill motor to drive a lathe. I have looked all over but haven't found anything close to what I want to use. I have gotten the PWM working but have hit a brick wall on Start/Stop. At power-up I want to have the PWM signal at 0% then when I press “Start” have it go to whatever is currently dialed in on the potentiometer. And on “Stop” just take signal back to 0. My cobbled together code has both run indication and stop indication and I was trying to use this to send the appropriate values on to the PWM calculations. Currently I have an Attiny85 that just ramps the signal up and down with no other control.
const int buttonPin[] = {2,3};
const int onled = 13;
const int offled = 12;
int buttonState = 0;
int outPin = 11;
int pot = A0;
int potValue = 0;
boolean running = true;
void setup() {
pinMode(outPin, OUTPUT);
Serial.begin(9600);
pinMode(onled, OUTPUT);
pinMode(offled, OUTPUT);
// initialize the pushbutton pin as an input:
for(int x=0; x<2; x++)
{
pinMode(buttonPin[x], INPUT);
}
}
void loop(){
for(int x=0; x<2; x++)
{
buttonState = digitalRead(buttonPin[x]);
if (buttonState == HIGH && buttonPin[x] == 2) {
// switch LEDs:
digitalWrite(onled, HIGH);
digitalWrite(offled, LOW);
}
if (buttonState == HIGH && buttonPin[x] == 3) {
// switch LEDs:
digitalWrite(onled, LOW);
digitalWrite(offled, HIGH);
}
{
potValue = analogRead(pot);
potValue = map(potValue,0,1023,10,45);
delay(potValue);
digitalWrite(outPin, LOW);
delay(50 - potValue);
Serial.println(potValue);
}
}
}