I have a Memsic accelerometer hooked up to my Uno which controls the movement of 1 servo. Thats working pretty good. What I would like to know is the following: I want to be able to use three push buttons. For each button I want it to use different paramters. For instance one push button would use an if/else to move the servo. The second pushbutton would just move the servo to a certain position and the third would do whatever. So whatever button I use would trump the rest and the program would only follow whats in that specific buttons code.
What is the setup/or structure called so I can do this? or if you know of an example that has already been dont that would be great.
system
August 2, 2011, 5:15pm
2
and the third would do whatever
Specification. Yeah!
You need to post the code you already have.
Will do tonight when I get home from work.
In the mean time can you tell me the name of the statement that could possibly work for this?
system
August 2, 2011, 5:29pm
4
No, there is no single "statement" - we need to see how you have your buttons set up.
Thats the problem. I dont have a button setup. I was hopping i could get an idea from here, add it to my code,and then if it didnt work post it.
Tonight when i get home i will attempt it again and then post it
Thanks
Below is the code I have to control a servo with a memsic 2125. The code works fine as is.
What I want is two buttons which causes the servo to work differently depending on the button pressed.
So for example if I pressed button 1 it would read the if else assigned to button 1 and if I pressed button 2 it would read another if else.
How would I go about doing this? What statement would I use?
#include <Servo.h>
const int xPin = 2; // X output of the accelerometer
const int yPin = 3; // Y output of the accelerometer
Servo myservo;
int val;
void setup() {
Serial.begin(9600);
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
myservo.attach(9);
}
void loop() {
int pulseX, pulseY;
int accelerationX, accelerationY;
pulseX = pulseIn(xPin,HIGH);
pulseY = pulseIn(yPin,HIGH);
accelerationX = ((pulseX / 10) - 500) * 8;
accelerationY = ((pulseY / 10) - 500) * 8;
val = (accelerationX);
val = map(val, 0,1000,0,90);
if (accelerationX >0)
{
myservo.write(val);
}
else
{
myservo.write(-val);
}
Serial.print(accelerationX);
Serial.print("\t");
Serial.print(accelerationY);
Serial.println();
delay(100);
}
system
August 4, 2011, 7:03am
7
So for example if I pressed button 1 it would read the if else assigned to button 1
I don't understand what you mean by this - you don't "read" an if/else, you execute one or the other.
Thanks for the correction. So all I want is when I press a momentary push button for one command to continuously loop until I press another button.