MUstar

IoT 아두이노 0630 - EX-HD1

Jun 30th, 2017
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <MsTimer2.h>
  2.  
  3. int sw[5] ={2,3,4,5,6};
  4. int pin_STEP[8] = {8, 9, 10, 11};
  5. int pin_STEP2[8] = {11, 10, 9, 8};
  6. int sp=1000, ip_sw=0 ;
  7.  
  8. void setup() {
  9.   int i;
  10.   for(i=0; i<5; i++)
  11.     pinMode(sw[i],INPUT_PULLUP);
  12.   for(i=0;i<4;i++)
  13.     pinMode(pin_STEP[i], OUTPUT);
  14.   STEP_out(0xF);
  15.   MsTimer2::set(7, STEP_ISR);
  16.   MsTimer2::start();
  17.  
  18. }
  19.  
  20. void loop() {
  21.   //루프따위는 장식입니다.
  22. }
  23.  
  24. void STEP_out(uint8_t da){
  25.   if (digitalRead(sw[0]) == HIGH) {if(sp>0)sp-=100;}           //SPEED UP
  26.     else if (digitalRead(sw[1]) == HIGH) {if(sp<10000)sp+=100;}//SPEED DOWN
  27.     else if(digitalRead(sw[2]) == HIGH) ip_sw = 2;             //LEFT
  28.     else if(digitalRead(sw[3]) == HIGH) ip_sw = 1;             //RIGHT
  29.   if(ip_sw==1){for(int i=0; i<4; i++){digitalWrite(pin_STEP[i], (da>>i)&0x01);}}
  30.   else if(ip_sw==2){for(int i=0; i<4; i++){digitalWrite(pin_STEP2[i], (da>>i)&0x01);}}
  31.  
  32. }
  33.  
  34. void STEP_ISR(void)
  35. {
  36.   static int i=0;
  37.   STEP_out (0x0F);
  38.   STEP_out(~(0x01<<i));
  39.   delay(sp);
  40.   if(i == 3){i=0;}
  41.   else{i++;}
  42. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×