i new arduino language.
i'm trying make rhythmic sound device using potentiometers , motor.
i have 2 potentiometers plugged a0 , a1 , receiving values.
i have gotten first potentiometer control speed of dc motor.
i want have second potentiometer control motor going on , off on 2 seconds...
pot2 full off mean motor off
pot2 in middle mean motor on 1 second , off 1 second
pot 2 full on mean motor on
i've tried find answer, may rely on using timer or t.oscillate. thank guidance.
my code_____________________________________________________________________
moderator edit: [code] [/code] tags added.
i'm trying make rhythmic sound device using potentiometers , motor.
i have 2 potentiometers plugged a0 , a1 , receiving values.
i have gotten first potentiometer control speed of dc motor.
i want have second potentiometer control motor going on , off on 2 seconds...
pot2 full off mean motor off
pot2 in middle mean motor on 1 second , off 1 second
pot 2 full on mean motor on
i've tried find answer, may rely on using timer or t.oscillate. thank guidance.
my code_____________________________________________________________________
code: [select]
int potpin1 = a0;
int potpin2 = a1;
int motorpin = 9;
int rpm = 0;
int motorvalue = 0;
int rhythm = 0;
void setup() {
serial.begin(9600);
}
void loop() {
rpm = analogread(potpin1);
rhythm = analogread(potpin2);
if (rpm>10) {
motorvalue = map(rpm, 0, 1023, 10, 255);
analogwrite(motorpin, motorvalue);
serial.print("rpm = " );
serial.print(motorvalue);
serial.print("\t rythym = " );
serial.print(rhythm);
serial.println();
delay(2);
}
}
moderator edit: [code] [/code] tags added.
turn motor on.
delaymillis.
turn motor off.
delaymillis.
the issue working out how long need delay.
use map() work out on time in milliseconds (map 0-1023 0-1000). first delay value, second delay 1000 - value.
delaymillis.
turn motor off.
delaymillis.
the issue working out how long need delay.
use map() work out on time in milliseconds (map 0-1023 0-1000). first delay value, second delay 1000 - value.
Arduino Forum > Using Arduino > Programming Questions > Turning a DC motor on and off
arduino
Comments
Post a Comment