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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4640|回復: 2
收起左側

發一個利用兩個IIC數字光傳感器(BH1750),進行平面定位

[復制鏈接]
ID:125150 發表于 2018-3-31 16:42 | 顯示全部樓層 |閱讀模式
看了去年電賽,在網上查呢下,很少有資料分享,最近剛好在做可見光定位,所以先將寫的兩個IIC數字光傳感器(BH1750),采用差分方式進行定位程序分享下,還在改進中,完成后將全部開放!(用的是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. /*--  調入了一幅圖像:這是您新建的圖像  --*/
  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);  //在坐標X0,Y0的位置開始顯示圖片  
  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. }

復制代碼

下載:
bh1750s.rar (1.32 KB, 下載次數: 22)
回復

使用道具 舉報

ID:454017 發表于 2019-4-14 10:19 來自手機 | 顯示全部樓層
樓主做完了嗎?我用51單片機去做,速度趕不趕得上
回復

使用道具 舉報

ID:560595 發表于 2019-6-28 15:55 | 顯示全部樓層
樓主做完了嗎?
回復

使用道具 舉報

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

本版積分規則

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

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 在线看无码的免费网站 | av毛片| 欧美激情第一区 | 国产精品99 | 国产精品视频网 | 日韩欧美视频免费在线观看 | 老熟女毛片 | 激情久久网 | 毛片链接| 久久99精品久久久97夜夜嗨 | 激情 亚洲 | 欧美精品乱码99久久影院 | 国产高清视频 | 在线视频国产一区 | 九九久久在线看 | 亚洲一在线 | 九九热这里 | 亚洲欧美一区二区三区视频 | 欧美精品一区二区免费 | 午夜在线 | 在线黄| 日本三级视频 | 免费麻豆视频 | 一级毛片视频免费观看 | 中文在线亚洲 | 成人影院网站ww555久久精品 | 天天操天天干天天曰 | 久久久一区二区三区 | 午夜激情影院 | 国产精品99久久久久久人 | 欧美日韩一区二区三区在线观看 | 色视频www在线播放国产人成 | 能看的av网站| 男女网站免费 | 国精产品一区一区三区免费完 | 国产a爽一区二区久久久 | 国产一区二区三区四区三区四 | 精品在线一区二区 | 亚洲大片 | 日韩精品在线一区 | 国产欧美日韩精品一区二区三区 |