SHARE
TWEET

Untitled

a guest Nov 17th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //云灯
  2. int ledPin1 =  7;   //D13是控制板L灯引脚
  3. int brightness = 0;   //呼吸灯明亮度
  4. int i = 5;
  5.  
  6. //振动感应灯1
  7. int zdPin = 2 ; //震动传感器D0脚接arduino板上D2口
  8. int ledPin =  13; //D13是控制板L灯引脚
  9. int zdState = 0;  //状态
  10.  
  11. //振动感应灯2
  12. int zdPin1 = 3 ; //震动传感器D0脚接arduino板上D2口
  13. int zdState1 = 0;
  14.  
  15.  
  16. //走马灯
  17. int LED1 = 8; // 第一个输出口
  18. int LED2 = 9;
  19. int LED3 = 10;
  20. int LED4 = 11;
  21. int LED5  = 12; // 最后一个输出口
  22.  
  23. //风扇
  24. const int P = A0; //电位器输入引脚
  25. const int U = 5;
  26. int sensorValue = 0; //电位器电压值
  27. int outputValue = 0;
  28.  
  29. //舵机
  30. #include <Servo.h>
  31. Servo myservo;
  32. int pos = 0;
  33.  
  34. void setup() {
  35.  
  36.   Serial.begin(9600);
  37.  
  38.   //舵机
  39.   myservo.attach(6);
  40.  
  41.   //云灯
  42.   pinMode(ledPin1, OUTPUT);
  43.   pinMode(ledPin, OUTPUT);
  44.  
  45.   //振动感应灯
  46.  
  47.   pinMode(zdPin, INPUT);
  48.  
  49.   //振动感应灯2
  50.   pinMode(zdPin1, INPUT);
  51.  
  52. }
  53.  
  54. void loop() {
  55.   pos1();   //舵机指针归零
  56.   //fengshan();   //风扇(?:会短路)
  57.   yundeng();    //云灯
  58.   DJLED();    //振动感应灯+舵机
  59.   LED();    //伞振动传感器灯
  60.  
  61. }
  62.  
  63. void yundeng() {
  64.   //云灯
  65.   /*digitalWrite(ledPin, HIGH);     //云灯闪烁效果
  66.   delay(105);
  67.   digitalWrite(ledPin, LOW );
  68.   delay(105);*/
  69.   digitalWrite(ledPin1, HIGH);    //云灯2常亮
  70.   delay(109);//延时一秒
  71.   //digitalWrite(ledPin1, LOW );    //伞改变云灯的闪烁效果
  72.   //delay(107);//延时一秒
  73.   analogWrite(ledPin, brightness);    //云灯1呼吸效果
  74.   brightness = brightness + i;
  75.   if (brightness == 0 || brightness == 255) {
  76.     i = -i;
  77.   }
  78.   delay(240);
  79. }
  80.  
  81. void DJLED() {
  82.   //振动感应灯+舵机
  83.   zdState = digitalRead(zdPin);
  84.   if (zdState == HIGH) {
  85.  
  86.     for (pos = 0; pos <= 180; pos += 5) {
  87.       myservo.write(pos);
  88.       delay(30);
  89.     }
  90.     for (pos = 180; pos >= 0; pos -= 5) {
  91.       myservo.write(pos);
  92.       delay(30);
  93.     }
  94.     delay(120);
  95.     /*digitalWrite(ledPin, HIGH);     //云灯LED效果
  96.       delay(100);//延时一秒*/
  97.   }
  98.   /*else {    //LED灯已删除
  99.     digitalWrite(ledPin, LOW );
  100.     delay(100);//延时一秒
  101.     }*/
  102. }
  103. void LED() {
  104.   //伞的振动传感器灯
  105.   zdState1 = digitalRead(zdPin1);
  106.   if (zdState1 == HIGH) {
  107.     /*digitalWrite(ledPin1, LOW );    //伞改变云灯的闪烁效果
  108.       delay(10);//延时一秒
  109.       digitalWrite(ledPin1, HIGH);
  110.       delay(10);//延时一秒*/
  111.     digitalWrite(LED1, HIGH);
  112.     digitalWrite(LED2, HIGH);
  113.     digitalWrite(LED3, HIGH);
  114.     digitalWrite(LED4, HIGH);
  115.     digitalWrite(LED5, HIGH);
  116.     delay(100);//延时一秒
  117.   }
  118.   else {
  119.     digitalWrite(LED1, LOW);
  120.     digitalWrite(LED2, LOW);
  121.     digitalWrite(LED3, LOW);
  122.     digitalWrite(LED4, LOW);
  123.     digitalWrite(LED5, LOW);
  124.  
  125.   }
  126. }
  127. void fengshan() {
  128.   //风扇
  129.   //读取模拟量值
  130.   sensorValue = analogRead(P);
  131.   outputValue = map(sensorValue, 0, 1023, 0, 255);
  132.   analogWrite(U, outputValue);
  133.   Serial.print("sensor=");
  134.   Serial.print(sensorValue);
  135.   Serial.print("\t output=");
  136.   Serial.println(outputValue);
  137.   delay(2);
  138. }
  139.  
  140. void pos1 () {
  141.   myservo.write(pos);
  142. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top