Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define STEP_PIN 6
- #define DIRECTION_PIN 7
- #define ENABLE_PIN 8
- #define GREEN_OUT 10
- #define BLUE_OUT 11
- #define RED_OUT 12
- #define WHITE_OUT 13
- #define STEPPER_GROUND 14
- #define YELLOW_OUT 15
- #define REVERSE_IN 16
- IntervalTimer FreqTimer;
- uint32_t RPM_30_MICROSECOND_DELAY = 147.; //A-1121=.8502 KHZ B-1126=.8500 KHZ
- uint32_t TmrInterval;
- int buttona = 0;
- int buttonb = 0;
- int buttonc = 0;
- int buttond = 0;
- int buttonCreep = 1;
- int PwrLEDState = 0;
- int TmrState = LOW;
- int SpeedRatio = 1;
- int n = 1;
- void setup() {
- TmrInterval = RPM_30_MICROSECOND_DELAY;
- FreqTimer.begin(STEPPER, TmrInterval);
- pinMode(9, INPUT);
- pinMode(3, INPUT); //Rcvr0 = B
- pinMode(5, INPUT); //Rcvr1 = D
- pinMode(2, INPUT); //Rcvr2 = A
- pinMode(4, INPUT); //Rcvr3 = C
- pinMode(REVERSE_IN, INPUT_PULLUP); //REVERSE CONTROL
- pinMode(RED_OUT, OUTPUT); //RED LED
- pinMode(GREEN_OUT, OUTPUT); //GREEN LED
- pinMode(BLUE_OUT, OUTPUT); //BLUE LED
- pinMode(WHITE_OUT, OUTPUT); //WHITE LED
- pinMode(STEPPER_GROUND, OUTPUT); //STEPPER GROUND CONTROL FET
- pinMode(STEP_PIN, OUTPUT);
- pinMode(DIRECTION_PIN, OUTPUT);
- pinMode(ENABLE_PIN, OUTPUT);
- pinMode(YELLOW_OUT, OUTPUT);
- digitalWrite(BLUE_OUT, LOW);
- digitalWrite(DIRECTION_PIN, HIGH);
- digitalWrite(STEPPER_GROUND, LOW);
- digitalWrite(RED_OUT, LOW);
- digitalWrite(WHITE_OUT, LOW);
- digitalWrite(YELLOW_OUT, HIGH);
- digitalWrite(STEP_PIN, LOW);
- digitalWrite(DIRECTION_PIN, LOW);
- if ((digitalRead(REVERSE_IN)) < 1) digitalWrite(DIRECTION_PIN, HIGH);
- digitalWrite(ENABLE_PIN, HIGH);
- digitalWrite(9, HIGH);
- //Serial.begin(9600);
- }
- void STEPPER(void) {
- if (n > SpeedRatio) {
- if (TmrState == LOW)
- {
- TmrState = HIGH;
- n = 1;
- }
- else {
- TmrState = LOW;
- n = 1;
- }
- }
- n = n + 1;
- digitalWrite(STEP_PIN, TmrState);
- }
- void loop() {
- buttonCreep = digitalRead(9);
- buttona = digitalRead(4);
- buttonb = digitalRead(2);
- buttonc = digitalRead(5);
- buttond = digitalRead(3);
- if (buttona > 0)
- {
- if (PwrLEDState < 1)
- {
- digitalWrite(WHITE_OUT, HIGH); // Turn the White LED on
- PwrLEDState = 1;
- digitalWrite(ENABLE_PIN, HIGH); //STOP STEPPER
- digitalWrite(YELLOW_OUT, LOW); // Turn the Yellow LED off
- }
- else
- {
- digitalWrite(WHITE_OUT, LOW); // Turn the White LED off
- PwrLEDState = 0;
- digitalWrite(ENABLE_PIN, HIGH); //STOP STEPPER
- digitalWrite(BLUE_OUT, LOW);
- digitalWrite(GREEN_OUT, LOW);
- digitalWrite(RED_OUT, LOW);
- digitalWrite(STEPPER_GROUND, LOW); //TURN OFF CONTROLLER
- digitalWrite(YELLOW_OUT, HIGH); // Turn the Yellow LED on
- }
- delay(1000);
- }
- else if (buttonb > 0 && (PwrLEDState == 1))
- {
- digitalWrite(GREEN_OUT, HIGH);
- SpeedRatio = 4;
- digitalWrite(ENABLE_PIN, LOW);
- digitalWrite(BLUE_OUT, LOW);
- digitalWrite(RED_OUT, LOW);
- digitalWrite(STEPPER_GROUND, HIGH);
- }
- else if (buttonc > 0 && (PwrLEDState == 1))
- {
- digitalWrite(BLUE_OUT, HIGH);
- SpeedRatio = 2;
- digitalWrite(ENABLE_PIN, LOW);
- digitalWrite(GREEN_OUT, LOW);
- digitalWrite(RED_OUT, LOW);
- digitalWrite(STEPPER_GROUND, HIGH);
- }
- else if (buttond > 0 && (PwrLEDState == 1))
- {
- digitalWrite(RED_OUT, HIGH);
- SpeedRatio = 1;
- digitalWrite(ENABLE_PIN, LOW);
- digitalWrite(GREEN_OUT, LOW);
- digitalWrite(BLUE_OUT, LOW);
- digitalWrite(STEPPER_GROUND, HIGH);
- }
- else if (buttonCreep < 1 && (PwrLEDState == 1))
- {
- SpeedRatio = 20;
- digitalWrite(ENABLE_PIN, LOW);
- digitalWrite(STEPPER_GROUND, HIGH);
- }
- else
- {
- //
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement