Advertisement
Guest User

Untitled

a guest
Sep 15th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.78 KB | None | 0 0
  1.  
  2. #define STEP_PIN                6
  3. #define DIRECTION_PIN           7
  4. #define ENABLE_PIN              8
  5. #define GREEN_OUT               10
  6. #define BLUE_OUT                11
  7. #define RED_OUT                 12
  8. #define WHITE_OUT               13
  9. #define STEPPER_GROUND          14
  10. #define YELLOW_OUT              15
  11. #define REVERSE_IN              16
  12.  
  13. IntervalTimer FreqTimer;
  14.  
  15. uint32_t RPM_30_MICROSECOND_DELAY = 147.;  //A-1121=.8502 KHZ  B-1126=.8500 KHZ
  16. uint32_t TmrInterval;
  17. int buttona = 0;
  18. int buttonb = 0;
  19. int buttonc = 0;
  20. int buttond = 0;
  21. int buttonCreep = 1;
  22. int PwrLEDState = 0;
  23. int TmrState = LOW;
  24. int SpeedRatio = 1;
  25. int n = 1;
  26.  
  27.  
  28. void setup() {
  29.   TmrInterval = RPM_30_MICROSECOND_DELAY;
  30.   FreqTimer.begin(STEPPER, TmrInterval);
  31.   pinMode(9, INPUT);
  32.   pinMode(3, INPUT); //Rcvr0 = B
  33.   pinMode(5, INPUT); //Rcvr1 = D
  34.   pinMode(2, INPUT); //Rcvr2 = A
  35.   pinMode(4, INPUT); //Rcvr3 = C
  36.   pinMode(REVERSE_IN, INPUT_PULLUP); //REVERSE CONTROL
  37.   pinMode(RED_OUT, OUTPUT); //RED LED
  38.   pinMode(GREEN_OUT, OUTPUT); //GREEN LED
  39.   pinMode(BLUE_OUT, OUTPUT); //BLUE LED
  40.   pinMode(WHITE_OUT, OUTPUT); //WHITE LED
  41.   pinMode(STEPPER_GROUND, OUTPUT); //STEPPER GROUND CONTROL FET
  42.   pinMode(STEP_PIN, OUTPUT);
  43.   pinMode(DIRECTION_PIN, OUTPUT);
  44.   pinMode(ENABLE_PIN, OUTPUT);
  45.   pinMode(YELLOW_OUT, OUTPUT);
  46.   digitalWrite(BLUE_OUT, LOW);
  47.   digitalWrite(DIRECTION_PIN, HIGH);
  48.   digitalWrite(STEPPER_GROUND, LOW);
  49.   digitalWrite(RED_OUT, LOW);
  50.   digitalWrite(WHITE_OUT, LOW);
  51.   digitalWrite(YELLOW_OUT, HIGH);
  52.   digitalWrite(STEP_PIN, LOW);
  53.   digitalWrite(DIRECTION_PIN, LOW);
  54.   if ((digitalRead(REVERSE_IN)) < 1) digitalWrite(DIRECTION_PIN, HIGH);
  55.   digitalWrite(ENABLE_PIN, HIGH);
  56.   digitalWrite(9, HIGH);
  57.   //Serial.begin(9600);
  58. }
  59.  
  60. void STEPPER(void) {
  61.  
  62.   if (n > SpeedRatio) {
  63.     if (TmrState == LOW)
  64.     {
  65.       TmrState = HIGH;
  66.       n = 1;
  67.     }
  68.     else {
  69.       TmrState = LOW;
  70.       n = 1;
  71.     }
  72.   }
  73.   n = n + 1;
  74.   digitalWrite(STEP_PIN, TmrState);
  75. }
  76.  
  77. void loop()  {
  78.  
  79.   buttonCreep = digitalRead(9);
  80.   buttona = digitalRead(4);
  81.   buttonb = digitalRead(2);
  82.   buttonc = digitalRead(5);
  83.   buttond = digitalRead(3);
  84.  
  85.   if (buttona > 0)
  86.   {
  87.     if (PwrLEDState < 1)
  88.     {
  89.       digitalWrite(WHITE_OUT, HIGH);   // Turn the White LED on
  90.       PwrLEDState = 1;
  91.       digitalWrite(ENABLE_PIN, HIGH);  //STOP STEPPER
  92.       digitalWrite(YELLOW_OUT, LOW);  // Turn the Yellow LED off
  93.     }
  94.     else
  95.     {
  96.       digitalWrite(WHITE_OUT, LOW);    // Turn the White LED off
  97.       PwrLEDState = 0;
  98.       digitalWrite(ENABLE_PIN, HIGH);  //STOP STEPPER
  99.       digitalWrite(BLUE_OUT, LOW);
  100.       digitalWrite(GREEN_OUT, LOW);
  101.       digitalWrite(RED_OUT, LOW);
  102.       digitalWrite(STEPPER_GROUND, LOW);  //TURN OFF CONTROLLER
  103.       digitalWrite(YELLOW_OUT, HIGH);  // Turn the Yellow LED on
  104.     }
  105.     delay(1000);
  106.   }
  107.   else if (buttonb > 0 && (PwrLEDState == 1))
  108.   {
  109.     digitalWrite(GREEN_OUT, HIGH);
  110.     SpeedRatio = 4;
  111.     digitalWrite(ENABLE_PIN, LOW);
  112.     digitalWrite(BLUE_OUT, LOW);
  113.     digitalWrite(RED_OUT, LOW);
  114.     digitalWrite(STEPPER_GROUND, HIGH);
  115.   }
  116.   else if (buttonc > 0 && (PwrLEDState == 1))
  117.   {
  118.     digitalWrite(BLUE_OUT, HIGH);
  119.     SpeedRatio = 2;
  120.     digitalWrite(ENABLE_PIN, LOW);
  121.     digitalWrite(GREEN_OUT, LOW);
  122.     digitalWrite(RED_OUT, LOW);
  123.     digitalWrite(STEPPER_GROUND, HIGH);
  124.   }
  125.  
  126.   else if (buttond > 0 && (PwrLEDState == 1))
  127.   {
  128.     digitalWrite(RED_OUT, HIGH);
  129.     SpeedRatio = 1;
  130.     digitalWrite(ENABLE_PIN, LOW);
  131.     digitalWrite(GREEN_OUT, LOW);
  132.     digitalWrite(BLUE_OUT, LOW);
  133.     digitalWrite(STEPPER_GROUND, HIGH);
  134.   }
  135.  
  136.   else if (buttonCreep < 1 && (PwrLEDState == 1))
  137.   {
  138.     SpeedRatio = 20;
  139.     digitalWrite(ENABLE_PIN, LOW);
  140.     digitalWrite(STEPPER_GROUND, HIGH);
  141.   }
  142.  
  143.   else
  144.   {
  145.     //
  146.   }
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement