Code Arduino Hdd

Published on January 2017 | Categories: Documents | Downloads: 27 | Comments: 0 | Views: 147
of 2
Download PDF   Embed   Report

Comments

Content

The code is very simple, here is mine, I am not sure if I used this exact code i
n the video, you might need to tinker with it.
int
int
int
int

phase1 = 2;
phase2 = 3;
phase3 = 4;
led = 12;

unsigned long stepLength = 40000;
int minStepLength = 1400;
int steps = 5;
void setup() {
pinMode(led, OUTPUT);
pinMode(phase1, OUTPUT);
pinMode(phase2, OUTPUT);
pinMode(phase3, OUTPUT);
digitalWrite(led, LOW);
}
void loop() {
switchStep(1);
switchStep(2);
switchStep(3);
if(stepLength > minStepLength)
{
stepLength = stepLength - steps;
} else {
// set the minimum pulse length
stepLength=minStepLength;
}
if (stepLength < 39950) {
digitalWrite(led, HIGH);
steps = 300;
}
if (stepLength < 20000) {
digitalWrite(led, LOW);
steps = 50;
}

// second gear

if (stepLength < 3000) {
digitalWrite(led, HIGH);
steps = 2;
}
}
void switchStep(int stage)
{
switch(stage)
{
case 1:
digitalWrite(phase1, HIGH);
digitalWrite(phase2, LOW);
digitalWrite(phase3, LOW);
myDelay(stepLength);
break;

// third gear

// fourth gear

case 2:
digitalWrite(phase1, LOW);
digitalWrite(phase2, HIGH);
digitalWrite(phase3, LOW);
myDelay(stepLength);
break;
default:
digitalWrite(phase1, LOW);
digitalWrite(phase2, LOW);
digitalWrite(phase3, HIGH);
myDelay(stepLength);
break;
}
}
void myDelay(unsigned long p) {
if (p > 16380) {
delay (p/1000);
} else {
delayMicroseconds(p);
}
}

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close