The Stepper Motor - Arduino
#include afmotor.h
AF_Stepper LeftMotor(48, 1);
int position = 1;
void setup() {
Serial.begin(9600);
Serial.println("Stepper test!");
LeftMotor.setSpeed(250);
}
void loop() {
if(Serial.available()){
Serial.println("Available");
char ch = Serial.read();
switch(ch){
case '+':
if (position == 0){
LeftMotor.step(2250, FORWARD, SINGLE);
position = 1;
Serial.println(position);
}
break;
case '-':
if (position == 1){
LeftMotor.step(2250, BACKWARD, SINGLE);
position = 0;
Serial.println(position);
}
break;
}
}
}
The LDR - Arduino
int PhotoA = 3;
int LEDpin = 13;
int valueA = 0;
int threshold = 500;
void setup(){
pinMode(PhotoA, INPUT);
pinMode(LEDpin, OUTPUT);
Serial.begin(9600);
}
void loop(){
valueA = analogRead(PhotoA);
if (valueA is less than threshold){
digitalWrite(LEDpin, HIGH);
Serial.print('+');
}
else {
digitalWrite(LEDpin, LOW);
Serial.print('-');
}
delay(1000);
}
The Link - Processing
import processing.serial.*;
Serial MotorPort;
Serial LDRPort;
void setup()
{
size(720, 720);
colorMode(RGB, 1.0);
noStroke();
rectMode(CENTER);
frameRate(100);
println(Serial.list());
MotorPort = new Serial(this, Serial.list()[0],9600);
LDRPort = new Serial(this, Serial.list()[2],9600);
}
void draw()
{
char ch = LDRPort.readChar();
MotorPort.write(ch);
}
Fairly simple code this time. Got the job done.
No comments:
Post a Comment