haha brrrrr
parent
fab9131e33
commit
5ac00b6243
45
src/main.cpp
45
src/main.cpp
|
@ -1,25 +1,48 @@
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
// Set LED_BUILTIN if it is not defined by Arduino framework
|
#define DIR_PIN 2
|
||||||
// #define LED_BUILTIN 13
|
#define STEP_PIN 3
|
||||||
|
#define STEPS_PER_REV 200
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
// initialize LED digital pin as an output.
|
|
||||||
pinMode(LED_BUILTIN, OUTPUT);
|
pinMode(LED_BUILTIN, OUTPUT);
|
||||||
|
pinMode(STEP_PIN, OUTPUT);
|
||||||
|
pinMode(DIR_PIN, OUTPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int pinState = LOW;
|
||||||
|
int speedDelay = 50;
|
||||||
|
int speedDelayDir = +1;
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// turn the LED on (HIGH is the voltage level)
|
digitalWrite(DIR_PIN, LOW);
|
||||||
digitalWrite(LED_BUILTIN, HIGH);
|
for (int i = 0; i < STEPS_PER_REV; i++)
|
||||||
|
{
|
||||||
|
digitalWrite(STEP_PIN, HIGH);
|
||||||
|
delayMicroseconds(500);
|
||||||
|
digitalWrite(STEP_PIN, LOW);
|
||||||
|
delayMicroseconds(500);
|
||||||
|
|
||||||
// wait for a second
|
delayMicroseconds(speedDelay);
|
||||||
delay(1000);
|
|
||||||
|
|
||||||
// turn the LED off by making the voltage LOW
|
if (speedDelay > 5000){
|
||||||
digitalWrite(LED_BUILTIN, LOW);
|
speedDelayDir = -1;
|
||||||
|
} else if (speedDelay < 50){
|
||||||
|
speedDelayDir = +1;
|
||||||
|
}
|
||||||
|
|
||||||
// wait for a second
|
if (speedDelayDir == +1) {
|
||||||
delay(1000);
|
speedDelay += 50;
|
||||||
|
} else {
|
||||||
|
speedDelay -= 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
pinState = !pinState;
|
||||||
|
digitalWrite(LED_BUILTIN, pinState);
|
||||||
|
|
||||||
|
// delay(500);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue