久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3961|回復: 2
打印 上一主題 下一主題
收起左側

第一個arduino uno見笑 acg激光傳感,dht11,3.2寸tft顯示屏

[復制鏈接]
跳轉到指定樓層
樓主
新手代碼寫得比較亂,也沒大標注,設備:arduino uno,acg激光傳感,dht11,3.2寸tft顯示屏。所用到的庫見附件。
  1. #include <Adafruit_GFX.h>    // Core graphics library
  2. #include <Adafruit_TFTLCD.h> // Hardware-specific library
  3. #include <dht11.h>
  4. dht11 DHT11;
  5. #define BLACK   0x0000
  6. #define BLUE    0x001F
  7. #define RED     0xF800
  8. #define GREEN   0x07E0
  9. #define CYAN    0x07FF
  10. #define MAGENTA 0xF81F
  11. #define YELLOW  0xFFE0
  12. #define WHITE   0xFFFF
  13. #define LCD_CS A3 // Chip Select goes to Analog 3
  14. #define LCD_CD A2 // Command/Data goes to Analog 2
  15. #define LCD_WR A1 // LCD Write goes to Analog 1
  16. #define LCD_RD A0 // LCD Read goes to Analog 0
  17. #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  18. #define DHT11PIN 10 //tmp pin

  19. uint8_t d[28];
  20. uint8_t c;
  21. bool logData = false;
  22. int i=0;
  23. int j=0;
  24. int k=0;
  25. int l=0;
  26. int m=0;
  27. int pm25=0;
  28. int opm25=0;
  29. int pm10=0;
  30. int opm10=0;
  31. int hum=0;
  32. int tem=0;
  33. double Aqi=0;

  34. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  35. // If using the shield, all control and data lines are fixed, and
  36. // a simpler declaration can optionally be used:
  37. // Adafruit_TFTLCD tft;
  38. //Adafruit_GFX_Button buttons[15];

  39. void setup() {

  40.   Serial.begin(9600);
  41.   pinMode(11,OUTPUT);
  42.   pinMode(12,OUTPUT);
  43.   digitalWrite(12,HIGH);
  44.   tft.reset();
  45.   uint16_t identifier = tft.readID();
  46. if(identifier == 0x9325) {
  47.   Serial.println(F("Found ILI9325 LCD driver"));}
  48.   else{Serial.print(F("Unknown LCD driver chip: "));
  49.   return;}
  50.   tft.begin(identifier);
  51.   tft.setRotation(1);
  52.   testtext();

  53. }

  54. void loop() {
  55.   
  56.   while(Serial.available()){
  57.     int sum=0;
  58.     c=Serial.read();
  59.     if(c==50){c=Serial.read();
  60.       if(c==61){c=Serial.read();
  61.       if(c==0){c=Serial.read();
  62.       if(c=28){c=Serial.read();
  63.       logData=true;}}}}
  64.    if(logData)
  65.       {d[i]=c;  //Serial.print(d[i]); Serial.print(",");Serial.println(i);
  66.        i=i+1;}
  67.    if(i==28){if(j==0){opm25=0;opm10=0;}
  68.      sum=d[0]+d[1]+d[2]+d[3]+d[4]+d[5]+d[6]+d[7]+d[8]+d[9]+d[10]+d[11]+d[12]+d[13]+d[14]+d[15]+d[16]+d[17]+d[18]+d[19]+d[20]+d[21]+d[22]+d[23]+d[24]+d[25];
  69.      if(sum==d[26]*256+d[27]-139){j=j+1;opm25=opm25+d[2]*256+d[3];opm10=opm10+d[4]*256+d[5];}
  70.      sum=0;logData = false;i=0;
  71.      //Serial.print(opm25); Serial.print(",");Serial.print(opm10);Serial.print(",");Serial.println(j);
  72.     }
  73.   }      
  74. if(l==0)
  75. {
  76.   dText();
  77.   pm25=opm25/j;pm10=opm10/j;j=0;l=6;
  78.   if(pm25<0)pm25=8;if(pm10<0)pm10=8;
  79.   DHT11.read(DHT11PIN);   //int chk =DHT11.read(DHT11PIN)
  80.   hum=DHT11.humidity;tem=DHT11.temperature;
  81.   uText();
  82.    if(pm25>60)k=k+1;
  83.    if(k>5){digitalWrite(11,HIGH);k=k+1;}
  84.    if(k>360){digitalWrite(11,LOW);k=0;}
  85.    if(pm25<70)m=m+1;
  86.    if(m>=50){digitalWrite(12,LOW);m=m+1;}
  87.    if(m>=400){digitalWrite(12,HIGH);m=0;}
  88. }
  89. //Serial.print((float)DHT11.humidity,2);Serial.print(",");Serial.println((float)DHT11.temperature, 2);
  90. //Serial.print(pm25);Serial.print(",");Serial.println(pm10);
  91. //Serial.print(k);;Serial.print(",");Serial.println(m);//Serial.println(getAQI(umg3));
  92.   l=l-1;delay(800);

  93. }

  94. unsigned long testtext()
  95. {
  96.   tft.fillScreen(BLACK);
  97.   unsigned long start = micros();
  98.   tft.setTextSize(2);tft.println("Tmp:");tft.setCursor(128,50);tft.println("oC");
  99.   tft.setCursor(157,2);tft.print("Pm25:");tft.setCursor(280,35);tft.println("ug");tft.setCursor(280,50);tft.println("/m3");
  100.   tft.setCursor(0,70);  tft.println("Hum:");tft.setCursor(140,120);tft.println("%");
  101.   tft.setCursor(157,70);  tft.println("Aqi:");tft.setCursor(280,105);//tft.println("ug");tft.setCursor(280,120);tft.println("/m3");
  102.   tft.setCursor(0,54);tft.println("__________________________");
  103.   tft.setCursor(150,0);tft.println("|");tft.setCursor(150,12);tft.println("|");tft.setCursor(150,24);tft.println("|");
  104.   tft.setCursor(150,36);tft.println("|");tft.setCursor(150,48);tft.println("|");tft.setCursor(150,60);tft.println("|");
  105.   tft.setCursor(150,72);tft.println("|");tft.setCursor(150,84);tft.println("|");tft.setCursor(150,96);tft.println("|");
  106.   tft.setCursor(150,108);tft.println("|");tft.setCursor(150,120);tft.println("|");
  107.   tft.setCursor(0,150);  tft.setTextColor(GREEN);tft.setTextSize(5);tft.print("Wolf");
  108.   tft.setCursor(155,140);tft.setTextSize(1);tft.setTextColor(RED);tft.print("*");
  109.   tft.setCursor(152,144);tft.print("**");
  110.   tft.setCursor(149,148);tft.print("***");
  111.   tft.setCursor(152,152);tft.print("**");
  112.   tft.setCursor(155,156);tft.print("*");
  113.   tft.setCursor(152,160);tft.setTextSize(2);tft.print("|");
  114.   tft.setCursor(200,150);tft.setTextColor(GREEN);tft.setTextSize(5);tft.println("Hui");
  115.   tft.setTextSize(1);
  116.   tft.println();
  117.   tft.println("Life is troubling my body,but I dealing it like my");
  118.   tft.println("first love.God helps those who help themselves.");
  119.   tft.println("in the life with my blurglecruncheon,");
  120.   tft.println("see if I can or not!");
  121.   return micros() - start;
  122. }
  123. unsigned long uText() {   
  124.   uint16_t cpm25 = GREEN;uint16_t cpm10 = GREEN;uint16_t colotm = GREEN;uint16_t colohu = GREEN;double q25=getAQI(pm25);double q10=getAQI(pm10);
  125.    if(pm25<=35)cpm25=WHITE;if(pm25>35&&pm25<=60)cpm25=YELLOW;if(pm25>60&&pm25<=150)cpm25=RED; if(pm25>150&&pm25<250)cpm25=MAGENTA;if(pm25>=250)cpm25=CYAN;
  126.    if(Aqi<=50)cpm10=BLUE;if(Aqi>50&&Aqi<=100)cpm10=YELLOW;if(Aqi>100&&Aqi<=150)cpm10=RED; if(Aqi>150&&Aqi<200)cpm10=MAGENTA;if(Aqi>=200)cpm10=CYAN;
  127.    if(hum<40)colohu=RED;   if(hum>40&&hum<70)colohu=GREEN;if(hum>=70)colohu=BLUE;
  128.    if(tem<=18)colotm=BLUE; if(tem>18&&tem<25)colotm=GREEN;if(tem>=25)colotm=RED;
  129.    if(q25>q10)Aqi=q25;else Aqi=q10;
  130.   tft.setTextSize(4);
  131.   tft.setCursor(200,30); tft.setTextColor(cpm25); tft.println(pm25);
  132.   tft.setCursor(170,100); tft.setTextColor(cpm10);tft.println(Aqi);
  133.   tft.setCursor(50,30);   tft.setTextColor(colotm); tft.println(tem);
  134.   tft.setCursor(50,100);  tft.setTextColor(colohu); tft.println(hum);
  135. }
  136.   
  137. unsigned long dText()
  138. {
  139.   tft.setCursor(50, 30); tft.setTextColor(BLACK);
  140.   tft.setTextSize(4);  tft.println(tem);
  141.   tft.setCursor(50, 100); tft.println(hum);
  142.   tft.setCursor(200, 30);tft.println(pm25);
  143.   tft.setCursor(170, 100);tft.println(Aqi);
  144.   
  145. }

  146. double getAQI(double pm25) {
  147.   double aqiL = 0;double aqiH = 0;double bpL = 0;double bpH = 0;double aqi = 0;//根據pm2.5和aqi對應關系分別計算aqi
  148.   if (pm25 >= 0 && pm25 <= 35) {
  149.     aqiL = 0;aqiH = 50;bpL = 0;bpH = 35;
  150.   } else if (pm25 > 35 && pm25 <= 75) {
  151.     aqiL = 50;aqiH = 100;bpL = 35;bpH = 75;
  152.   } else if (pm25 > 75 && pm25 <= 115) {
  153.     aqiL = 100; aqiH = 150;bpL = 75; bpH = 115;
  154.   } else if (pm25 > 115 && pm25 <= 150) {
  155.     aqiL = 150;aqiH = 200;bpL = 115; bpH = 150;
  156.   } else if (pm25 > 150 && pm25 <= 250) {
  157.     aqiL = 200;aqiH = 300;bpL = 150;bpH = 250;
  158.   } else if (pm25 > 250 && pm25 <= 350) {
  159.     aqiL = 300;aqiH = 400; bpL = 250; bpH = 350;
  160.   } else if (pm25 > 350) {
  161.     aqiL = 400; aqiH = 500; bpL = 350;bpH = 500;
  162.   }
  163.   //公式aqi = (aqiH - aqiL) / (bpH - bpL) * (desity - bpL) + aqiL;
  164.   aqi = (aqiH - aqiL) / (bpH - bpL) * (pm25 - bpL) + aqiL;
  165.   return aqi;
  166. }
復制代碼


IMG_20171012_200335_EDIT_1.jpg (687.89 KB, 下載次數: 173)

IMG_20171012_200335_EDIT_1.jpg
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:238956 發表于 2017-10-12 20:14 | 只看該作者
  1. #include <Adafruit_GFX.h>    // Core graphics library
  2. #include <Adafruit_TFTLCD.h> // Hardware-specific library
  3. #include <dht11.h>
  4. dht11 DHT11;
  5. #define BLACK   0x0000
  6. #define BLUE    0x001F
  7. #define RED     0xF800
  8. #define GREEN   0x07E0
  9. #define CYAN    0x07FF
  10. #define MAGENTA 0xF81F
  11. #define YELLOW  0xFFE0
  12. #define WHITE   0xFFFF
  13. #define LCD_CS A3 // Chip Select goes to Analog 3
  14. #define LCD_CD A2 // Command/Data goes to Analog 2
  15. #define LCD_WR A1 // LCD Write goes to Analog 1
  16. #define LCD_RD A0 // LCD Read goes to Analog 0
  17. #define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
  18. #define DHT11PIN 10 //tmp pin

  19. uint8_t d[28];
  20. uint8_t c;
  21. bool logData = false;
  22. int i=0;
  23. int j=0;
  24. int k=0;
  25. int l=0;
  26. int m=0;
  27. int pm25=0;
  28. int opm25=0;
  29. int pm10=0;
  30. int opm10=0;
  31. int hum=0;
  32. int tem=0;
  33. double Aqi=0;

  34. Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
  35. // If using the shield, all control and data lines are fixed, and
  36. // a simpler declaration can optionally be used:
  37. // Adafruit_TFTLCD tft;
  38. //Adafruit_GFX_Button buttons[15];

  39. void setup() {

  40.   Serial.begin(9600);
  41.   pinMode(11,OUTPUT);
  42.   pinMode(12,OUTPUT);
  43.   digitalWrite(12,HIGH);
  44.   tft.reset();
  45.   uint16_t identifier = tft.readID();
  46. if(identifier == 0x9325) {
  47.   Serial.println(F("Found ILI9325 LCD driver"));}
  48.   else{Serial.print(F("Unknown LCD driver chip: "));
  49.   return;}
  50.   tft.begin(identifier);
  51.   tft.setRotation(1);
  52.   testtext();

  53. }

  54. void loop() {
  55.   
  56.   while(Serial.available()){
  57.     int sum=0;
  58.     c=Serial.read();
  59.     if(c==50){c=Serial.read();
  60.       if(c==61){c=Serial.read();
  61.       if(c==0){c=Serial.read();
  62.       if(c=28){c=Serial.read();
  63.       logData=true;}}}}
  64.    if(logData)
  65.       {d[i]=c;  //Serial.print(d[i]); Serial.print(",");Serial.println(i);
  66.        i=i+1;}
  67.    if(i==28){if(j==0){opm25=0;opm10=0;}
  68.      sum=d[0]+d[1]+d[2]+d[3]+d[4]+d[5]+d[6]+d[7]+d[8]+d[9]+d[10]+d[11]+d[12]+d[13]+d[14]+d[15]+d[16]+d[17]+d[18]+d[19]+d[20]+d[21]+d[22]+d[23]+d[24]+d[25];
  69.      if(sum==d[26]*256+d[27]-139){j=j+1;opm25=opm25+d[2]*256+d[3];opm10=opm10+d[4]*256+d[5];}
  70.      sum=0;logData = false;i=0;
  71.      //Serial.print(opm25); Serial.print(",");Serial.print(opm10);Serial.print(",");Serial.println(j);
  72.     }
  73.   }      
  74. if(l==0)
  75. {
  76.   dText();
  77.   pm25=opm25/j;pm10=opm10/j;j=0;l=6;
  78.   if(pm25<0)pm25=8;if(pm10<0)pm10=8;
  79.   DHT11.read(DHT11PIN);   //int chk =DHT11.read(DHT11PIN)
  80.   hum=DHT11.humidity;tem=DHT11.temperature;
  81.   uText();
  82.    if(pm25>60)k=k+1;
  83.    if(k>5){digitalWrite(11,HIGH);k=k+1;}
  84.    if(k>360){digitalWrite(11,LOW);k=0;}
  85.    if(pm25<70)m=m+1;
  86.    if(m>=50){digitalWrite(12,LOW);m=m+1;}
  87.    if(m>=400){digitalWrite(12,HIGH);m=0;}
  88. }
  89. //Serial.print((float)DHT11.humidity,2);Serial.print(",");Serial.println((float)DHT11.temperature, 2);
  90. //Serial.print(pm25);Serial.print(",");Serial.println(pm10);
  91. //Serial.print(k);;Serial.print(",");Serial.println(m);//Serial.println(getAQI(umg3));
  92.   l=l-1;delay(800);

  93. }

  94. unsigned long testtext()
  95. {
  96.   tft.fillScreen(BLACK);
  97.   unsigned long start = micros();
  98.   tft.setTextSize(2);tft.println("Tmp:");tft.setCursor(128,50);tft.println("oC");
  99.   tft.setCursor(157,2);tft.print("Pm25:");tft.setCursor(280,35);tft.println("ug");tft.setCursor(280,50);tft.println("/m3");
  100.   tft.setCursor(0,70);  tft.println("Hum:");tft.setCursor(140,120);tft.println("%");
  101.   tft.setCursor(157,70);  tft.println("Aqi:");tft.setCursor(280,105);//tft.println("ug");tft.setCursor(280,120);tft.println("/m3");
  102.   tft.setCursor(0,54);tft.println("__________________________");
  103.   tft.setCursor(150,0);tft.println("|");tft.setCursor(150,12);tft.println("|");tft.setCursor(150,24);tft.println("|");
  104.   tft.setCursor(150,36);tft.println("|");tft.setCursor(150,48);tft.println("|");tft.setCursor(150,60);tft.println("|");
  105.   tft.setCursor(150,72);tft.println("|");tft.setCursor(150,84);tft.println("|");tft.setCursor(150,96);tft.println("|");
  106.   tft.setCursor(150,108);tft.println("|");tft.setCursor(150,120);tft.println("|");
  107.   tft.setCursor(0,150);  tft.setTextColor(GREEN);tft.setTextSize(5);tft.print("Wolf");
  108.   tft.setCursor(155,140);tft.setTextSize(1);tft.setTextColor(RED);tft.print("*");
  109.   tft.setCursor(152,144);tft.print("**");
  110.   tft.setCursor(149,148);tft.print("***");
  111.   tft.setCursor(152,152);tft.print("**");
  112.   tft.setCursor(155,156);tft.print("*");
  113.   tft.setCursor(152,160);tft.setTextSize(2);tft.print("|");
  114.   tft.setCursor(200,150);tft.setTextColor(GREEN);tft.setTextSize(5);tft.println("Hui");
  115.   tft.setTextSize(1);
  116.   tft.println();
  117.   tft.println("Life is troubling my body,but I dealing it like my");
  118.   tft.println("first love.God helps those who help themselves.");
  119.   tft.println("in the life with my blurglecruncheon,");
  120.   tft.println("see if I can or not!");
  121.   return micros() - start;
  122. }
  123. unsigned long uText() {   
  124.   uint16_t cpm25 = GREEN;uint16_t cpm10 = GREEN;uint16_t colotm = GREEN;uint16_t colohu = GREEN;double q25=getAQI(pm25);double q10=getAQI(pm10);
  125.    if(pm25<=35)cpm25=WHITE;if(pm25>35&&pm25<=60)cpm25=YELLOW;if(pm25>60&&pm25<=150)cpm25=RED; if(pm25>150&&pm25<250)cpm25=MAGENTA;if(pm25>=250)cpm25=CYAN;
  126.    if(Aqi<=50)cpm10=BLUE;if(Aqi>50&&Aqi<=100)cpm10=YELLOW;if(Aqi>100&&Aqi<=150)cpm10=RED; if(Aqi>150&&Aqi<200)cpm10=MAGENTA;if(Aqi>=200)cpm10=CYAN;
  127.    if(hum<40)colohu=RED;   if(hum>40&&hum<70)colohu=GREEN;if(hum>=70)colohu=BLUE;
  128.    if(tem<=18)colotm=BLUE; if(tem>18&&tem<25)colotm=GREEN;if(tem>=25)colotm=RED;
  129.    if(q25>q10)Aqi=q25;else Aqi=q10;
  130.   tft.setTextSize(4);
  131.   tft.setCursor(200,30); tft.setTextColor(cpm25); tft.println(pm25);
  132.   tft.setCursor(170,100); tft.setTextColor(cpm10);tft.println(Aqi);
  133.   tft.setCursor(50,30);   tft.setTextColor(colotm); tft.println(tem);
  134.   tft.setCursor(50,100);  tft.setTextColor(colohu); tft.println(hum);
  135. }
  136.   
  137. unsigned long dText()
  138. {
  139.   tft.setCursor(50, 30); tft.setTextColor(BLACK);
  140.   tft.setTextSize(4);  tft.println(tem);
  141.   tft.setCursor(50, 100); tft.println(hum);
  142.   tft.setCursor(200, 30);tft.println(pm25);
  143.   tft.setCursor(170, 100);tft.println(Aqi);
  144.   
  145. }

  146. double getAQI(double pm25) {
  147.   double aqiL = 0;double aqiH = 0;double bpL = 0;double bpH = 0;double aqi = 0;//根據pm2.5和aqi對應關系分別計算aqi
  148.   if (pm25 >= 0 && pm25 <= 35) {
  149.     aqiL = 0;aqiH = 50;bpL = 0;bpH = 35;
  150.   } else if (pm25 > 35 && pm25 <= 75) {
  151.     aqiL = 50;aqiH = 100;bpL = 35;bpH = 75;
  152.   } else if (pm25 > 75 && pm25 <= 115) {
  153.     aqiL = 100; aqiH = 150;bpL = 75; bpH = 115;
  154.   } else if (pm25 > 115 && pm25 <= 150) {
  155.     aqiL = 150;aqiH = 200;bpL = 115; bpH = 150;
  156.   } else if (pm25 > 150 && pm25 <= 250) {
  157.     aqiL = 200;aqiH = 300;bpL = 150;bpH = 250;
  158.   } else if (pm25 > 250 && pm25 <= 350) {
  159.     aqiL = 300;aqiH = 400; bpL = 250; bpH = 350;
  160.   } else if (pm25 > 350) {
  161.     aqiL = 400; aqiH = 500; bpL = 350;bpH = 500;
  162.   }
  163.   //公式aqi = (aqiH - aqiL) / (bpH - bpL) * (desity - bpL) + aqiL;
  164.   aqi = (aqiH - aqiL) / (bpH - bpL) * (pm25 - bpL) + aqiL;
  165.   return aqi;
  166. }
復制代碼


回復

使用道具 舉報

板凳
ID:238956 發表于 2017-10-12 20:18 | 只看該作者

用到的庫

Desktop.rar

152.83 KB, 下載次數: 14, 下載積分: 黑幣 -5

回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 亚洲系列第一页 | 天天影视网天天综合色在线播放 | 亚洲国产成人精品女人久久久 | 亚洲精品日韩在线 | 皇色视频在线 | 欧美a在线 | 国产小视频在线 | 黑人巨大精品欧美一区二区免费 | 在线成人www免费观看视频 | 日韩久久成人 | 91精品亚洲 | 自拍偷拍中文字幕 | 天堂中文在线观看 | 亚洲国产精品一区在线观看 | 91久久国产综合久久 | 精品久久久久久久久久久久久久久久久 | 婷婷激情综合 | 欧美一区二区三区在线看 | 久久亚洲一区二区三区四区 | 91精品国产91久久久久游泳池 | www四虎影视 | 亚洲国产精品久久久久秋霞不卡 | 国产高清精品一区二区三区 | 成人一区二 | 国产精品一区在线 | 狠狠操电影 | 国产一区999| 国产激情视频 | 久久国产精品视频 | 国产精品免费播放 | 国产成人久久精品一区二区三区 | 久久久一区二区三区 | 亚洲成人一区 | 欧美中文字幕一区二区三区 | 久久99网| 天堂中文av | 夜久久 | 成人一区二区电影 | 日本午夜精品一区二区三区 | 成人av网页 | 亚洲一二三在线 |