#include "SevSeg.h"
#include <Stepper.h>
SevSeg sevseg;
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 40, 38, 36, 34);
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
myStepper.setSpeed(60);
pinMode(22, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
pinMode(26, INPUT_PULLUP);
pinMode(28, INPUT_PULLUP);
pinMode(30, INPUT_PULLUP);
pinMode(31, INPUT_PULLUP);
pinMode(32, INPUT_PULLUP);
pinMode(A0,OUTPUT);
pinMode(A1,OUTPUT);
pinMode(A2,OUTPUT);
pinMode(A3,OUTPUT);
pinMode(A4,OUTPUT);
pinMode(A5,OUTPUT);
pinMode(A6, OUTPUT);
byte numDigits = 1;
byte digitPins[] = {};
byte segmentPins[] = {4, 5, 6, 7, 8, 9, 10, 11};
bool resistorsOnSegments = true; // 'false' means resistors are on digit pins
byte hardwareConfig = COMMON_CATHODE; // See README.md for options
sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
sevseg.setBrightness(100);
}
void loop() {
// put your main code here, to run repeatedly:
sevseg.setNumber(getSwitchState());
sevseg.refreshDisplay();
int state = getSwitchState();
if(state != 0){
digitalWrite(A0, LOW);
}
if(state == 0){
digitalWrite(A0, HIGH);
}
if(state == 1){
motor();
}
if(state == 2){
led(A1);
}
if(state == 3){
led(A2);
}
if(state == 4){
led(A3);
}
if(state == 5){
led(A4);
}
if(state == 6){
led(A5);
}
if(state == 7){
led(A6);
}
}
int getSwitchState() {
/* edit this function to read the state of the three switches
and return the correct decimal number associated with the
position of each switch.
For example, if all switches are off, this function should
return 0. If only the right most switch is on, this function
should return 1, and so forth.
*/
int switchState = ((digitalRead(30))+(2*digitalRead(26))+(4*digitalRead(22)));
return switchState;
}
void motor() {
myStepper.step(stepsPerRevolution);
delay(500);
myStepper.step(-stepsPerRevolution);
delay(500);
}
int led(int p){
digitalWrite(p, HIGH);
delay(500);
digitalWrite(p, LOW);
delay(500);
}