MUstar

IoT 아두이노 0526 - no2

May 26th, 2017
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int vib = 23; //Vibrator
  2. int led = 6; //LED
  3. int sw[6] = {20,22,24,26,28,30}; // Switch
  4. int sp = 500; //speed
  5. int st; //Temp Value
  6. void setup() {
  7.   pinMode(vib, OUTPUT);
  8.   pinMode(led, OUTPUT);
  9.   pinMode(sw,INPUT_PULLUP);
  10.   //pinMode(sw2,INPUT_PULLUP);
  11.   //pinMode(sw3,INPUT_PULLUP);
  12.   //pinMode(sw4,INPUT_PULLUP);
  13.  
  14. }
  15.  
  16. void loop() {
  17.    st=0;
  18.    if(digitalRead(sw[5]) == HIGH){sp = 500;} //sp Clear
  19.    else if(digitalRead(sw[3]) == HIGH){ //ON
  20.    while(st<1){
  21.         if(digitalRead(sw[4]) == HIGH){st++;} //OFF
  22.         if(digitalRead(sw[1]) == HIGH){if(sp==50){continue;}sp-=50;} //SPEED UP
  23.         if(digitalRead(sw[2]) == HIGH){sp+=50;} //SPEED DOWN
  24.         digitalWrite(led,HIGH);
  25.         digitalWrite(vib,HIGH);
  26.         delay(sp);
  27.         digitalWrite(led,LOW);
  28.         digitalWrite(vib,LOW);
  29.         delay(sp);
  30.      }
  31.   }
  32. }
RAW Paste Data