Skip to content
Snippets Groups Projects
Commit dbb1524d authored by Xianzong Meng's avatar Xianzong Meng
Browse files

Arduino codes added

parent 5696379e
No related branches found
No related tags found
No related merge requests found
.Rproj.user
.Rhistory
.RData
.Ruserdata
bool switchState=0;
int x = 0;
byte incomingByte;
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
void setup() {
// initialize the serial port:
myStepper.setSpeed(300); //CHANGE SPEED HERE***
Serial.begin(9600);
pinMode(12,INPUT);
}
void loop() {
switchState=digitalRead(12);
if (Serial.available() != 0) {
incomingByte = Serial.read();
if (incomingByte == '1') {
x = 1;
delay(100);
}
}
if(switchState == HIGH){
x = 1;
delay(100);
}
if (x==1){
myStepper.step(800); // The motors has a step angle of 1.8 deg.***
delay(1000);
myStepper.step(-800);
delay(100);
Serial.end();
Serial.begin(9600);
x=0;
}
delayMicroseconds(50);
}
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment