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

 找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 4657|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

發(fā)一個(gè)利用兩個(gè)IIC數(shù)字光傳感器(BH1750),進(jìn)行平面定位

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:125150 發(fā)表于 2018-3-31 16:42 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
看了去年電賽,在網(wǎng)上查呢下,很少有資料分享,最近剛好在做可見(jiàn)光定位,所以先將寫(xiě)的兩個(gè)IIC數(shù)字光傳感器(BH1750),采用差分方式進(jìn)行定位程序分享下,還在改進(jìn)中,完成后將全部開(kāi)放!(用的是arduino UNOd的板子)

arduino源程序如下:
  1. #include <Wire.h> //BH1750 IIC Mode
  2. #include <math.h>
  3. #include <SPI.h>  
  4. #include <Wire.h>  
  5. #include <Adafruit_GFX.h>  
  6. #include <Adafruit_SSD1306.h>  
  7. int potpin=0;
  8. int a;//定義模擬接口0
  9. int now;
  10. int BH1750address0 = 0x5c; //setting i2c address
  11. int BH1750address1 = 0x23;
  12. uint16_t val0=0;
  13.   uint16_t val1=0;
  14. byte buff0[2];
  15. byte buff1[2];
  16. #define OLED_RESET 4  
  17. Adafruit_SSD1306 display(OLED_RESET);  
  18.   
  19. static const unsigned char PROGMEM logo[] =  
  20. {   

  21. /*--  調(diào)入了一幅圖像:這是您新建的圖像  --*/
  22. /*--  寬度x高度=128x64  --*/
  23. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  24. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  25. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  26. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  27. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  28. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  29. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  30. 0x00,0x00,0x00,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  31. 0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  32. 0x00,0x00,0x01,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  33. 0x00,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  34. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  35. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  36. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  37. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  38. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  39. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  40. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  42. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  43. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  44. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  45. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  46. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  47. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  48. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  49. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  50. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  51. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  52. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  53. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  54. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  55. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  56. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  57. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  58. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  59. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  60. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  61. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  62. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  63. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  64. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  65. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  66. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  67. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  68. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  69. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  70. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  71. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  72. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  73. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  74. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  75. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  76. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  77. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  78. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  79. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  80. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  81. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  82. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  83. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  84. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  85. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  86. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00

  87. };  
  88.    
  89. #if (SSD1306_LCDHEIGHT != 64)  
  90. #error("Height incorrect, please fix Adafruit_SSD1306.h!");  
  91. #endif  
  92.   int outputValue,outputValue1;
  93. void setup()
  94. {  outputValue=0;
  95.   outputValue1=0;      
  96.   Wire.begin();
  97.   Serial.begin(19200);
  98.   display.begin(SSD1306_SWITCHCAPVCC, 0x3C);   
  99.   display.clearDisplay();  
  100. }

  101. void loop()
  102. {a=analogRead(potpin);//讀取模擬接口0 的值,
  103.   int i,j;
  104. // uint16_t val0=0;
  105. // uint16_t val1=0;
  106.   BH1750_Init(BH1750address0);
  107.   BH1750_Init(BH1750address1);
  108.   delay(200);

  109.   if(2==BH1750_Read0(BH1750address0))
  110.   {
  111.     val0=((buff0[0]<<8)|buff0[1])/1.2;
  112.      Serial.print(now);
  113.   Serial.print( ",");
  114.     Serial.print(val0,DEC);     
  115.     Serial.print(",");
  116.       Serial.print(val1,DEC);     
  117.    Serial.print(",");
  118.        Serial.print(val1,DEC);     
  119.     Serial.print(";");
  120.   }
  121.   delay(10);

  122. if(2==BH1750_Read1(BH1750address1))
  123.   {
  124.     val1=((buff1[0]<<8)|buff1[1])/1.2;
  125.      Serial.print(now);
  126.   Serial.print( ",");
  127.     Serial.print(val0,DEC);     
  128.    Serial.print(",");
  129. Serial.print(val1,DEC);     
  130.     Serial.print(",");
  131.     Serial.print(val1,DEC);     
  132.     Serial.print(";");
  133.    
  134.   }
  135.   delay(10);
  136.   
  137.    outputValue = map(val0, 0, 700, 0, 64);
  138.     outputValue1 = map(val1, 0, 700, 0, 128);
  139.    display.drawBitmap(outputValue1,outputValue , logo, 128, 64,1);  //在坐標(biāo)X0,Y0的位置開(kāi)始顯示圖片  
  140.                                                //128是取模軟件顯示的寬度  
  141.                                                //64是取模軟件顯示的高度  
  142. display.display();                           //把緩存的都顯示  
  143.   delay(1);  
  144.    
  145.   display.clearDisplay();    //清除屏幕  
  146.   delay(10);
  147. }

  148. int BH1750_Read0(int address) //
  149. {
  150.   int i=0;
  151.   Wire.beginTransmission(address);
  152.   Wire.requestFrom(address, 2);
  153.   while(Wire.available()) //
  154.   {
  155.     buff0[i] = Wire.read();  // receive one byte
  156.     i++;
  157.   }
  158.     Wire.endTransmission();  
  159.     return i;
  160. }

  161. int BH1750_Read1(int address) //
  162. {
  163.   int j=0;
  164.   Wire.beginTransmission(address);
  165.   Wire.requestFrom(address, 2);
  166.   while(Wire.available()) //
  167.   {
  168.     buff1[j] = Wire.read();  // receive one byte
  169.     j++;
  170.   }
  171.   Wire.endTransmission();  
  172.   return j;
  173. }

  174. void BH1750_Init(int address)
  175. {
  176.   Wire.beginTransmission(address);
  177.   Wire.write(0x10);//1lx reolution 120ms
  178.   Wire.endTransmission();
  179. }

復(fù)制代碼

下載:
bh1750s.rar (1.32 KB, 下載次數(shù): 22)

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:454017 發(fā)表于 2019-4-14 10:19 來(lái)自手機(jī) | 只看該作者
樓主做完了嗎?我用51單片機(jī)去做,速度趕不趕得上
回復(fù)

使用道具 舉報(bào)

板凳
ID:560595 發(fā)表于 2019-6-28 15:55 | 只看該作者
樓主做完了嗎?
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表
主站蜘蛛池模板: 精品国产伦一区二区三区观看说明 | 精品一区二区在线观看 | 欧美一区二区三区在线观看 | 精品国产视频在线观看 | 国产女人第一次做爰毛片 | 嫩草最新网址 | 久久久久成人精品免费播放动漫 | 欧美一级在线免费观看 | 欧美一级一 | 中文字幕乱码一区二区三区 | 久久国产婷婷国产香蕉 | 91精品国产91 | a a毛片| 在线观看国产 | 成人h视频 | 国产黄色大片在线免费观看 | 99小视频 | 久久久91精品国产一区二区三区 | 欧美日韩一区二区三区视频 | 国产精品久久久久久妇女6080 | 国产精品久久久久久亚洲调教 | 欧美日韩国产三级 | 国内精品一区二区三区 | 国产探花在线精品一区二区 | 自拍偷拍中文字幕 | 国产免费又黄又爽又刺激蜜月al | 久久99精品久久久久久 | 午夜国产羞羞视频免费网站 | 国产精品一区二区三区99 | 国产一区不卡 | 国产激情一区二区三区 | 久久亚洲欧美日韩精品专区 | 国产激情视频网 | 一区二区三区亚洲视频 | 成人在线小视频 | www.久久99 | 日韩1区2区 | 浴室洗澡偷拍一区二区 | av在线免费观看网址 | 中文字幕亚洲视频 | 日日操夜夜干 |