Hi Guys, I'm new to Arduino so bear with me. I know a bit of C++ as well from RobotC
I hooked up a little motor to the arduino PWM ports. The motor has a built-in degree counter. When the degrees are even the signal is HIGH, and when the degrees are uneven the signal is LOW, meaning there's a 180 HIGH's in a full 360° rotation.
Right now I'm just testing to get a feel for the programming. I'm going to build an H-bridge in a few days when my parts arrive and like my program to work like this (only an example):
Run motor CW 80°
wait 1s
Run motor CW 175°
wait 5s
Run motor CCW 210°
wait 0,2s
Run motor CW 55°
It's a linear program sequence I need with many many lines. The amount of degrees it should turn would be calculated by a variable in a separate program sequence if possible that counts the amounts of degrees it turns.
Right now I just wrote a really simple program - proof of concept if you will. It's not working though, I don't think my counting function works properly as the motor just keeps on spinning and spinning.
int degree;
void setup() {
pinMode(9, OUTPUT);
pinMode(13, OUTPUT);
pinMode(2, INPUT);
}
void loop()
{
if (degree != 90) // If degree count doesn't equal 90 then
{
analogWrite(9, 102); //Run at 40% power
}
else
{
analogWrite(9, 0); //Stop Motor
}
if (digitalRead(2) == HIGH) // On-board motor switch
{
digitalWrite(13, HIGH);
degree++;
}
else
{
digitalWrite(13, LOW);
}
}
How would I go about programming a linear program like that without interference from secondary tasks like counting the degrees?