Servo metro
This commit is contained in:
+3
-2
@@ -10,7 +10,8 @@
|
|||||||
|
|
||||||
[env:uno]
|
[env:uno]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
# board = uno
|
|
||||||
board = sparkfun_promicro16
|
board = sparkfun_promicro16
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = https://github.com/DFRobot/DFRobotDFPlayerMini
|
lib_deps =
|
||||||
|
https://github.com/DFRobot/DFRobotDFPlayerMini
|
||||||
|
arduino-libraries/Servo@^1.3.0
|
||||||
|
|||||||
+11
-97
@@ -1,108 +1,22 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
|
#include <Servo.h>
|
||||||
|
|
||||||
// Buttons
|
#define SERVO_PIN6 6
|
||||||
#define LEFT_PIN20 20
|
#define READ_ANALOG8 8
|
||||||
#define RIGHT_PIN19 19
|
|
||||||
#define SPEED_PIN18 18
|
|
||||||
|
|
||||||
// Steper motor
|
Servo MYSERVO;
|
||||||
const int STEP_PIN5 = 5;
|
int ANGLE = 0;
|
||||||
const int DIR_PIN7 = 7;
|
|
||||||
int SPEED_INDEX = 2; // by defult is 2
|
|
||||||
|
|
||||||
// LEDs
|
|
||||||
const short int LA = 2;
|
|
||||||
const short int LB = 3;
|
|
||||||
const short int LC = 10;
|
|
||||||
const short int LD = 14;
|
|
||||||
const short int LE = 15;
|
|
||||||
const short int LF = 4;
|
|
||||||
const short int LG = 8;
|
|
||||||
const short int LDOT = 16;
|
|
||||||
|
|
||||||
// Setup Section
|
// Setup Section
|
||||||
void setup() {
|
void setup() {
|
||||||
// Stepper motor setup
|
MYSERVO.attach(SERVO_PIN6);
|
||||||
pinMode(STEP_PIN5, OUTPUT);
|
// pinMode(READ_ANALOG8, INPUT);
|
||||||
pinMode(DIR_PIN7, OUTPUT);
|
|
||||||
|
|
||||||
// Seven sgement setup
|
|
||||||
pinMode(LA, OUTPUT);
|
|
||||||
pinMode(LB, OUTPUT);
|
|
||||||
pinMode(LC, OUTPUT);
|
|
||||||
pinMode(LD, OUTPUT);
|
|
||||||
pinMode(LE, OUTPUT);
|
|
||||||
pinMode(LF, OUTPUT);
|
|
||||||
pinMode(LG, OUTPUT);
|
|
||||||
pinMode(LDOT, OUTPUT);
|
|
||||||
|
|
||||||
// Buttons setup
|
|
||||||
pinMode(LEFT_PIN20, INPUT);
|
|
||||||
pinMode(RIGHT_PIN19, INPUT);
|
|
||||||
pinMode(SPEED_PIN18, INPUT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop Section
|
// Loop Section
|
||||||
void loop() {
|
void loop() {
|
||||||
long int micro_seconds[3] = {600, 1000, 5000};
|
ANGLE = analogRead(READ_ANALOG8);
|
||||||
|
ANGLE = map(ANGLE, 0, 1023, 0, 180);
|
||||||
// Speed section
|
MYSERVO.write(ANGLE);
|
||||||
if (digitalRead(SPEED_PIN18) == LOW) {
|
delay(10);
|
||||||
SPEED_INDEX--;
|
|
||||||
if (SPEED_INDEX < 0)
|
|
||||||
SPEED_INDEX = 2;
|
|
||||||
delay(1000);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Display
|
|
||||||
switch (SPEED_INDEX) {
|
|
||||||
case 0:
|
|
||||||
digitalWrite(LA, LOW);
|
|
||||||
digitalWrite(LB, HIGH);
|
|
||||||
digitalWrite(LC, HIGH);
|
|
||||||
digitalWrite(LD, LOW);
|
|
||||||
digitalWrite(LE, LOW);
|
|
||||||
digitalWrite(LF, LOW);
|
|
||||||
digitalWrite(LG, LOW);
|
|
||||||
digitalWrite(LDOT, LOW);
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
digitalWrite(LA, HIGH);
|
|
||||||
digitalWrite(LB, HIGH);
|
|
||||||
digitalWrite(LC, LOW);
|
|
||||||
digitalWrite(LD, HIGH);
|
|
||||||
digitalWrite(LE, HIGH);
|
|
||||||
digitalWrite(LF, LOW);
|
|
||||||
digitalWrite(LG, HIGH);
|
|
||||||
digitalWrite(LDOT, LOW);
|
|
||||||
break;
|
|
||||||
case 2:
|
|
||||||
digitalWrite(LA, HIGH);
|
|
||||||
digitalWrite(LB, HIGH);
|
|
||||||
digitalWrite(LC, HIGH);
|
|
||||||
digitalWrite(LD, HIGH);
|
|
||||||
digitalWrite(LE, LOW);
|
|
||||||
digitalWrite(LF, LOW);
|
|
||||||
digitalWrite(LG, HIGH);
|
|
||||||
digitalWrite(LDOT, LOW);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (digitalRead(LEFT_PIN20) == LOW) {
|
|
||||||
digitalWrite(DIR_PIN7, HIGH);
|
|
||||||
|
|
||||||
digitalWrite(STEP_PIN5,HIGH);
|
|
||||||
delayMicroseconds(micro_seconds[SPEED_INDEX]);
|
|
||||||
digitalWrite(STEP_PIN5,LOW);
|
|
||||||
delayMicroseconds(micro_seconds[SPEED_INDEX]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (digitalRead(RIGHT_PIN19) == LOW) {
|
|
||||||
digitalWrite(DIR_PIN7, LOW);
|
|
||||||
|
|
||||||
digitalWrite(STEP_PIN5,HIGH);
|
|
||||||
delayMicroseconds(micro_seconds[SPEED_INDEX]);
|
|
||||||
digitalWrite(STEP_PIN5,LOW);
|
|
||||||
delayMicroseconds(micro_seconds[SPEED_INDEX]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user