the first code is for a muscle sensor kit, i need the code to say if the value of i is > 275 then move to the right and if i is < 275 move to the left. the servo motor will be moving right or left depending on i. i need help combining the two code into what i want! THANK YOU
servo motor code:
Muscle sensor code:
servo motor code:
Code:
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
Muscle sensor code:
Code:
// reads analog input from the five inputs from your arduino board
// and sends it out via serial
// variables for input pins and
int analogInput[6];
// variable to store the value
int value[6];
void setup()
{
// declaration of pin modes
for(int i=0;i<6;i++)
{
analogInput[i] = i+1;
value[i] = 0;
pinMode(analogInput[i], INPUT);
}
// begin sending over serial port
Serial.begin(9600);
}
void loop()
{
// read the value on analog input
for(int i=0;i<6;i++)
{
value[i] = analogRead(analogInput[i]);
}
// print out value over the serial port
for(int i=0;i<6;i++)
{
Serial.println(0 + i + 1); //prefix
Serial.println(value[i]);
}
// wait for a bit to not overload the port
delay(500);
}
Comment