Thursday, 24 September 2015
My Arduino Code
Explenation of the code is comming soon
Below is the code in the meantime, It is written in C++
The Code;
#include <AFMotor.h>
AF_DCMotor motorM1(1, MOTOR12_64KHZ); // create motor #1, 64KHz pwm
AF_DCMotor motorM2(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
AF_DCMotor motorM3(3, MOTOR12_64KHZ); // create motor #1, 64KHz pwm
AF_DCMotor motorM4(4, MOTOR12_64KHZ); // create motor #2, 64KHz pwm
int incomingByte = 0;
void setup() {
//set all the pins using as outputs:
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
Serial.begin(9600); // set up Serial library at 9600 bps
digitalWrite(A0, HIGH);
Serial.println("Motor test!");
motorM1.setSpeed(200); // set the speed to 200/255
motorM2.setSpeed(200); // set the speed to 200/255
motorM3.setSpeed(200); // set the speed to 200/255
motorM4.setSpeed(200); // set the speed to 200/255
}
void loop() {
if(Serial.available() > 0)
{
incomingByte = Serial.read();
//Motor 1
if(incomingByte == 'k')
{ //if (digitalWrite(Keybord entry
motorM1.run(FORWARD); // turn it on going forward
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 'i')
{ //if (digitalWrite(Keybord entry
motorM1.run(BACKWARD); // the other way
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == ',')
{ //if (digitalWrite(Keybord entry
motorM1.run(RELEASE); // stopped
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
//Motor 2
if(incomingByte == 'd')
{ //if (digitalWrite(Keybord entry
motorM2.run(FORWARD); // turn it on going forward
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 'e')
{ //if (digitalWrite(Keybord entry
motorM2.run(BACKWARD); // the other way
Serial.print("I received:22 ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 'c')
{ //if (digitalWrite(Keybord entry
motorM2.run(RELEASE); // stopped
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
//Motor 3
if(incomingByte == 'r')
{ //if (digitalWrite(Keybord entry
motorM3.run(FORWARD); // turn it on going forward
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 'f')
{ //if (digitalWrite(Keybord entry
motorM3.run(BACKWARD); // the other way
Serial.print("I received:22 ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 'v')
{ //if (digitalWrite(Keybord entry
motorM3.run(RELEASE); // stopped
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
//Motot 4
if(incomingByte == 'u')
{ //if (digitalWrite(Keybord entry
motorM4.run(FORWARD); // turn it on going forward
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 'j')
{ //if (digitalWrite(Keybord entry
motorM4.run(BACKWARD); // the other way
Serial.print("I received:22 ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 'm')
{ //if (digitalWrite(Keybord entry
motorM4.run(RELEASE); // stopped
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
//Motor 5
if(incomingByte == 'x')
{ //if (digitalWrite(Keybord entry
digitalWrite(A1, LOW); //set leg 1 of the H-Bridge high
digitalWrite(A2, LOW); //set leg 2 of the H-Bridge Low
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 's')
{ //if (digitalWrite(Keybord entry
digitalWrite(A1, LOW); //set leg 1 of the H-Bridge high
digitalWrite(A2, HIGH); //set leg 2 of the H-Bridge Low
Serial.print("I received:22 ");
Serial.println(incomingByte, DEC);
}
if(incomingByte == 'w')
{ //if (digitalWrite(Keybord entry
digitalWrite(A1, HIGH); //set leg 1 of the H-Bridge high
digitalWrite(A2, LOW); //set leg 2 of the H-Bridge Low
Serial.print("I received: ");
Serial.println(incomingByte, DEC);
}
// Led Controle
if(incomingByte == 'l' )
{
Serial.println("I received: l ");
digitalWrite(A3, HIGH); // turn the LED on (HIGH is the voltage level)
}
if(incomingByte == 'o')
{
Serial.println("I received: o ");
digitalWrite(A3, LOW); // turn the LED off by making the voltage LOW
}
}
}
Labels:
My Robotic Arm EPQ
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment