MUstar

IoT 아두이노 - 0519 프로젝트 (소스코드값만)

May 19th, 2017
65
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int pin_PIEZO = 12;
  2. int pin_GND1 = 3;
  3. int pin_GND2 = 8;
  4. int pin_LED[3] = {0,1,2};
  5. int pin_SW = 7;
  6. int scale_data[9] = {-255,130,146,164,174,195,220,246,261};
  7.  
  8. void setup(){
  9. pinMode(pin_PIEZO, OUTPUT);
  10. pinMode(pin_SW,INPUT_PULLUP);
  11. pinMode(pin_LED[0], OUTPUT);
  12. pinMode(pin_LED[1], OUTPUT);
  13. pinMode(pin_LED[2], OUTPUT);
  14. pinMode(pin_GND1, OUTPUT);
  15. pinMode(pin_GND2, OUTPUT);
  16. digitalWrite(pin_GND1, LOW);
  17. digitalWrite(pin_GND2, LOW);
  18. }
  19.  
  20. void loop(){
  21.   if(digitalRead(pin_SW) == LOW){
  22.   LED_control(1);delay(1000); LED_control(2);delay(1000); LED_control(4);delay(1000);LED_control(0);delay(1000);
  23.   tone(pin_PIEZO, scale_data[3]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(1);
  24.   tone(pin_PIEZO, scale_data[2]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(2);
  25.   tone(pin_PIEZO, scale_data[1]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(4);
  26.   tone(pin_PIEZO, scale_data[2]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(1);
  27.   tone(pin_PIEZO, scale_data[3]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(2);
  28.   tone(pin_PIEZO, scale_data[3]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(4);
  29.   tone(pin_PIEZO, scale_data[3]);delay(250);noTone(pin_PIEZO);delay(250);LED_control(1);
  30.   tone(pin_PIEZO, scale_data[2]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(2);
  31.   tone(pin_PIEZO, scale_data[2]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(4);
  32.   tone(pin_PIEZO, scale_data[2]);delay(250);noTone(pin_PIEZO);delay(250);LED_control(1);
  33.   tone(pin_PIEZO, scale_data[3]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(2);
  34.   tone(pin_PIEZO, scale_data[5]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(4);
  35.   tone(pin_PIEZO, scale_data[5]);delay(250);noTone(pin_PIEZO);delay(250);LED_control(1);
  36.   tone(pin_PIEZO, scale_data[3]);delay(187.5);noTone(pin_PIEZO);delay(187.5);LED_control(2);
  37.   tone(pin_PIEZO, scale_data[2]);delay(62.5);noTone(pin_PIEZO);delay(62.5);LED_control(4);
  38.   tone(pin_PIEZO, scale_data[1]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(1);
  39.   tone(pin_PIEZO, scale_data[2]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(2);
  40.   tone(pin_PIEZO, scale_data[3]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(4);
  41.   tone(pin_PIEZO, scale_data[3]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(1);
  42.   tone(pin_PIEZO, scale_data[3]);delay(250);noTone(pin_PIEZO);delay(250);LED_control(2);
  43.   tone(pin_PIEZO, scale_data[2]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(4);
  44.   tone(pin_PIEZO, scale_data[2]);delay(125);noTone(pin_PIEZO);delay(125);LED_control(1);
  45.   tone(pin_PIEZO, scale_data[3]);delay(187.5);noTone(pin_PIEZO);delay(187.5);LED_control(2);
  46.   tone(pin_PIEZO, scale_data[2]);delay(62.5);noTone(pin_PIEZO);delay(62.5); LED_control(4);
  47.   tone(pin_PIEZO, scale_data[1]);delay(500);noTone(pin_PIEZO);delay(500);LED_control(0);
  48.   }
  49.   else{
  50.   digitalWrite(pin_LED, LOW);
  51.   digitalWrite(pin_PIEZO, LOW);
  52.   }
  53. }
  54.  
  55. void LED_control(uint8_t da)
  56. {
  57.   digitalWrite(pin_LED[0], da & 0x01);
  58.   da >>= 1;
  59.   digitalWrite(pin_LED[1], da & 0x01);
  60.   da >>= 1;
  61.   digitalWrite(pin_LED[2], da & 0x01);
  62. }
RAW Paste Data