Stepper motor with buttons and seven segment. (it was cool)
This commit is contained in:
+2
-1
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
[env:uno]
|
[env:uno]
|
||||||
platform = atmelavr
|
platform = atmelavr
|
||||||
board = uno
|
# board = uno
|
||||||
|
board = sparkfun_promicro16
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps = https://github.com/DFRobot/DFRobotDFPlayerMini
|
lib_deps = https://github.com/DFRobot/DFRobotDFPlayerMini
|
||||||
|
|||||||
+92
-26
@@ -1,42 +1,108 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include <SoftwareSerial.h>
|
|
||||||
#include "DFRobotDFPlayerMini.h"
|
|
||||||
|
|
||||||
int music_num;
|
// Buttons
|
||||||
SoftwareSerial mySoftwareSerial(10, 11); // #1
|
#define LEFT_PIN20 20
|
||||||
DFRobotDFPlayerMini myDFPlayer; // #2
|
#define RIGHT_PIN19 19
|
||||||
|
#define SPEED_PIN18 18
|
||||||
|
|
||||||
|
// Steper motor
|
||||||
|
const int STEP_PIN5 = 5;
|
||||||
|
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() {
|
||||||
mySoftwareSerial.begin(9600);
|
// Stepper motor setup
|
||||||
Serial.begin(115200);
|
pinMode(STEP_PIN5, OUTPUT);
|
||||||
myDFPlayer.begin(mySoftwareSerial); // #3
|
pinMode(DIR_PIN7, OUTPUT);
|
||||||
myDFPlayer.volume(20);
|
|
||||||
|
// 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() {
|
||||||
if (Serial.available() > 0) {
|
long int micro_seconds[3] = {600, 1000, 5000};
|
||||||
music_num = Serial.readString().toInt(); // #4
|
|
||||||
if (music_num < 5 && music_num > 0) {
|
// Speed section
|
||||||
switch (music_num) {
|
if (digitalRead(SPEED_PIN18) == LOW) {
|
||||||
|
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:
|
case 1:
|
||||||
Serial.println("1");
|
digitalWrite(LA, HIGH);
|
||||||
myDFPlayer.play(1);
|
digitalWrite(LB, HIGH);
|
||||||
|
digitalWrite(LC, LOW);
|
||||||
|
digitalWrite(LD, HIGH);
|
||||||
|
digitalWrite(LE, HIGH);
|
||||||
|
digitalWrite(LF, LOW);
|
||||||
|
digitalWrite(LG, HIGH);
|
||||||
|
digitalWrite(LDOT, LOW);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
Serial.println("2");
|
digitalWrite(LA, HIGH);
|
||||||
myDFPlayer.play(2);
|
digitalWrite(LB, HIGH);
|
||||||
break;
|
digitalWrite(LC, HIGH);
|
||||||
case 3:
|
digitalWrite(LD, HIGH);
|
||||||
Serial.println("3");
|
digitalWrite(LE, LOW);
|
||||||
myDFPlayer.play(3);
|
digitalWrite(LF, LOW);
|
||||||
break;
|
digitalWrite(LG, HIGH);
|
||||||
case 4:
|
digitalWrite(LDOT, LOW);
|
||||||
Serial.println("4");
|
|
||||||
myDFPlayer.play(4);
|
|
||||||
break;
|
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