Hi,
I have a pair of vibration motors that alternately buzz. At the moment the on / off is managed by delay() which takes it's value from a potentiometer via an int potValue. The response to me turning the pot is slooow, so I'd like to ditch the delay (). The code is here -
int leftBuz = 3;
int rightBuz = 5;
int potPin = A0;
int potValue = 0;
void setup()
{
pinMode(leftBuz, OUTPUT);
pinMode (rightBuz, OUTPUT);
pinMode (potPin, INPUT);
Serial.begin (9600);
}
void loop()
{
potValue = analogRead (potPin);
Serial.println(potValue);
delay (2);
analogWrite(leftBuz, 153);
delay (potValue);
analogWrite(leftBuz, 0);
delay (potValue);
analogWrite (rightBuz, 153);
delay (potValue);
analogWrite (rightBuz, 0);
delay (potValue);
}
All of the tutorials suggest millis which is about time, but my HIGH or LOW is all about values 0-1023 from a potentiometer, which is dynamic.
So I'm going for a 'quicker' button and a 'slower' button and then count button presses. This could give me something like a 0-9 integer called 'stepSpeed' or similar (the idea is to promote stepping in my neurology patients - I'm a physio).
But how do I take this number and use it to control the frequency of a HIGH to LOW change in two motors?
I'd love some ideas, or example code, I don't need the finished thing, thanks!!
Cheers,
Al.