MUstar

IoT 아두이노 0630 - STEP_MOTOR

Jun 29th, 2017
63
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <MsTimer2.h>
  2.  
  3. int pin_STEP[8] = {8, 9, 10, 11};
  4.  
  5. void setup() {
  6.   int i;
  7.   for(i=0;i<4;i++)
  8.     pinMode(pin_STEP[i], OUTPUT);
  9.     STEP_out(0xF);
  10.     MsTimer2::set(10, STEP_ISR);
  11.     MsTimer2::start();
  12. }
  13.  
  14. void loop() {
  15. }
  16. void STEP_out(uint8_t da){
  17.   for(int i=4; i>0; i++)
  18.     digitalWrite(pin_STEP[i], (da>>i) & 0x01);
  19. }
  20.  
  21. void STEP_ISR(void)
  22. {
  23.   static int i=0;
  24.   STEP_out (0x0F);
  25.   STEP_out(~(0x01<<i));
  26.   if(i == 3){i=0;}
  27.   else{i++;}
  28. }
RAW Paste Data