欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標(biāo)題: Arduino開(kāi)關(guān)鍵控鎖程序,自動(dòng)門 [打印本頁(yè)]

作者: Mr-Sa    時(shí)間: 2019-11-18 16:00
標(biāo)題: Arduino開(kāi)關(guān)鍵控鎖程序,自動(dòng)門
  1. #include <Servo.h>
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. #include<Stepper.h>

  5. LiquidCrystal_I2C lcd(0x27,16,2);  //配置LCD地址及行列
  6. Servo myservo;        //創(chuàng)建一個(gè)舵機(jī)控制對(duì)象

  7. int led1=3;         //定義LED1引腳
  8. int led2=4;         //定義LED2引腳
  9. int buzzer=5;         //定義蜂鳴器引腳
  10. int button=6;         //定義按鍵引腳
  11. int length;           //定義一個(gè)變量用來(lái)表示共有多少個(gè)音符
  12. int steps=512;
  13. Stepper myStepper(steps, 8, 9, 10, 11);

  14. int song[] =
  15. {
  16.   /*  歌曲頻率*/
  17. 589, 495, 441, 495,  
  18.   -1, 589, 495, 441, 589,
  19. 495,  -1, 495, 495, 495, 441, 495, -1, 495,
  20. 589, 495, 441, 589, 495,  -1,
  21. };

  22. float duration[]=
  23. {  
  24.   /*  持續(xù)的時(shí)間 單位 ms */
  25.    1,    1, 0.5, 0.5,
  26.    1,  0.5, 0.5, 0.5, 0.5,
  27.    1,  0.5, 0.5, 0.5,   1, 0.5, 1, 0.5, 0.5,
  28.    0.5,0.5, 0.5, 0.5,   1,   1,
  29. };

  30. void setup()
  31. {  
  32.   {            
  33.   pinMode(led1,OUTPUT);     //3號(hào)數(shù)字口設(shè)置為輸出狀態(tài)
  34.   pinMode(led2,OUTPUT);     //4號(hào)數(shù)字口設(shè)置為輸出狀態(tài)
  35.   }
  36.   pinMode(buzzer,OUTPUT);
  37.   length = sizeof(song) / sizeof(song[0]);  //這里用了一個(gè)sizeof函數(shù),查出數(shù)組里有多少個(gè)音符
  38.   for (int x = 0; x < length; x++)          //循環(huán)音符的次數(shù)
  39.    {
  40.      tone(buzzer, song[x]);     //依次播放tune數(shù)組元素,即每個(gè)音符
  41.      delay(400 * duration[x]);  //每個(gè)音符持續(xù)的時(shí)間,即節(jié)拍duration,400是調(diào)整時(shí)間的越大,曲子速度越慢,越小曲子速度越快
  42.      noTone(buzzer);            //停止當(dāng)前音符,進(jìn)入下一音符
  43.    }
  44.    {
  45.   Serial.begin(9600);
  46.   myservo.attach(2);         //綁定對(duì)象至D7
  47.   }
  48.   {
  49.     // 設(shè)置轉(zhuǎn)速,單位r/min
  50.     myStepper.setSpeed(20);

  51.     // 初始化串口
  52.     Serial.begin(9600);
  53.   }
  54. }

  55. void duoji1()
  56. {
  57.    myservo.write(150);                 //寫入角度
  58.    Serial.println(myservo.read());     //打印舵機(jī)角度
  59. }

  60. void duoji2()
  61. {
  62.    myservo.write(0);                 //寫入角度
  63.    Serial.println(myservo.read());     //打印舵機(jī)角度
  64. }

  65. void duoji3()
  66. {
  67.    myservo.write(10);                 //寫入角度
  68.    Serial.println(myservo.read());    //打印舵機(jī)角度
  69. }
  70. void clockwise()
  71. {
  72.   // 順時(shí)針一次旋轉(zhuǎn)
  73.     Serial.println();
  74.     myStepper.step(520);
  75.     delay(1000);
  76. }
  77. void clockwises()
  78. {
  79.   // 順時(shí)針一次旋轉(zhuǎn)
  80.     Serial.println();
  81.     myStepper.step(-520);
  82.     delay(1000);
  83. }

  84. void xianshi1()
  85. {  
  86.    lcd.init();                 //初始化LCD
  87.    lcd.backlight();            //打開(kāi)背光
  88.    lcd.setCursor(3,0);         //設(shè)置顯示位置
  89.    lcd.print("Welcome to ");   //顯示字符數(shù)據(jù)
  90.    lcd.setCursor(5,1);         //設(shè)置顯示位置
  91.    lcd.print("Home !");        //顯示字符數(shù)據(jù)
  92.   }
  93. void xianshi2()
  94. {
  95.    lcd.init();              //初始化LCD
  96.    lcd.backlight();         //打開(kāi)背光
  97.    lcd.setCursor(4,0);      //設(shè)置顯示位置
  98.    lcd.print("Good Bye");   //顯示字符數(shù)據(jù)
  99.    lcd.setCursor(4,1);      //設(shè)置顯示位置
  100.    lcd.print("*Locked*");   //顯示字符數(shù)據(jù)
  101. }
  102. void loop()
  103. {
  104.     jiance();
  105. }

  106. void jiance()

  107. {
  108.   int buttonState = digitalRead(button); // 檢測(cè)按鍵
  109.   delay(1000);
  110.   int n =digitalRead(button);            //創(chuàng)建一個(gè)變量n,按鍵狀態(tài)采集出來(lái)賦值給他。
  111.   if (n==HIGH)           //判斷n是否為高電平,如果是執(zhí)行下面的語(yǔ)句,不是則跳過(guò)。
  112.   {
  113.      
  114.      digitalWrite(led2,LOW);           //LED2滅
  115.      digitalWrite(led1,HIGH);          //LED1亮
  116.      xianshi1();               //運(yùn)行xianshi
  117.      delay(1000);
  118.      duoji1();              //運(yùn)行xianshi
  119.      setup();   
  120.      delay(1000);
  121.      clockwise();                //運(yùn)行xianshi
  122.      delay(11000);


  123.      
  124.      digitalWrite(led1,LOW);          //LED1滅
  125.      digitalWrite(led2,HIGH);          //LED2亮
  126.      xianshi2();               //運(yùn)行xianshi2
  127.       setup();   
  128.      clockwises();
  129.      delay(1000);
  130.      duoji2();              //運(yùn)行xianshi
  131.      delay(1000);
  132.      duoji3();              //運(yùn)行duoji3
  133.    }
  134. }
復(fù)制代碼

作者: admin    時(shí)間: 2019-11-20 14:55
本帖需要重新編輯補(bǔ)全電路原理圖,源碼,詳細(xì)說(shuō)明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1