Okay, I have been tearing my hair out trying to get this project to work for a little over a week. I am working on an Uno, using the 0022 IDE and drivers in Vista and 7. I thought it best to put it here because of what it's doing.
I have been trying (and failing) to get my board to play nice with an Adafruit motor shield. This is supposed to be the driving force (no pun intended) behind a robot that I am trying to build. I can get one if/else statement to behave beautifully, but if I add anything more than that, and it ignores the conditions of every one but the first, resulting in a ton of garbage coming out (I have been trying to debug it one loop at a time, . The directional input was originally supposed to be given by means of five momentary switches for simplicity's sake. I have tried separate if/else statements, if/else if, switch/case arguments, switching pins, and quite frankly I'm at a loss as to what could be going wrong. The motor that I'm using to test the code is a vibration motor salvaged from an off-branded Nintendo Gamecube controller.
I'll upload the code in a little bit, once I get on to my other computer.
You have 3 cases here which don't make sense at all:
If power is not low
If power is low
Some third case (power is neither low, nor not low) - this will never happen
I would start by reworking that along these lines:
if (power != LOW)
{
motor1.run(RELEASE);
}
// here if power is low
else
{
if (back==LOW)
{
motor1.run(BACKWARD);
}
else
{
motor1.run(BRAKE);
}
} // end power low
Gave that a try; no dice. Tried changing pins and switches, as well. It works fine if I'm checking the values for going forward, but for some reason it is being unnecessarily obtuse when I try to go backward.
I looked at the circuit, and I noticed that if I touched a voltmeter to pin 5, the motor started behaving. Damnedest thing. I still haven't begun to figure out how to use that to my advantage.
Edit: Screw it - I think one of my last experiments may have blown some of the pins. I already had another Uno coming for a different project, so I'm going to try it with some virgin hardware.
Okay, it's something with the board, but not with the ATMega chip. Fired up the new board, and it presented the same symptoms, so I poked around with the code.
My code calls for digital pins 2,5,6,9,and 10 to be initialized as inputs. I tried changing the pin that turned the motor on, and discovered that pins 2 and 10 are the only ones that actually behave. I have no idea how to proceed further.
Actually, that is the input that I actually can make work, so I'm not entirely sure it's a conflict. I'm checking now against the list on the Adafruit forums, but I believe that pin is not used.
Okay, so pin 2 isn't used, but pins 5 and 6, which are both supposed to be used for input, are supposed to be used for motors 3 and 4, which aren't used. I'm wondering if that could cause some kind of funky interference?
Okay, I have found one way to fix my problem (going to try turning on the internal pull-up resistors later on in hopes that will solve the original problem) - I just connected the input from pin 5 to pin A0, and added the following line:
back=analogRead(A0);
Suddenly, it works now. It needs some debouncing, if my diagnosing skills are correct, but it works.