703浏览
查看: 703|回复: 2

【试用测评】FireBeetle ESP32-E扩展板——晃动灯 方向灯

[复制链接]
本帖最后由 云天 于 2021-8-16 13:07 编辑

IMG_20210812_165454.jpg


【晃动灯】
1、数字震动传感器
360截图20210816123405262.jpg

本开关在静止时为开路(OFF)状态,当受到外力碰触而达到适当震动力时,或移动速度达到适当离(偏)心力时,导电接脚会发生瞬间导通(ON)状态,使电气特性改变,而当外力消失时电气特性恢复开路(OFF)状态。无方向性,任何角度均可以触发工作。
IMG_20210816_111010_edit_43397328241294.jpg

IMG_20210816_111015_edit_43406572451709.jpg

  1. #include <Adafruit_NeoPixel.h>
  2. #define PIN_LED 16     
  3. #define NUM_LED 1
  4. int shake =25;   
  5. Adafruit_NeoPixel pixels(NUM_LED, PIN_LED, NEO_GRB + NEO_KHZ800);
  6. void setup() {
  7.   // put your setup code here, to run once:
  8.   pixels.begin();
  9.   pinMode(shake, INPUT);
  10.   pinMode(16, OUTPUT);
  11.   Serial.begin(9600);
  12. }
  13. void loop() {
  14.   pixels.clear();
  15.   int State = digitalRead(shake);
  16.   Serial.println(State);
  17.   if(State==0){
  18.     pixels.setBrightness(200);
  19.     pixels.setPixelColor(0, pixels.Color(int(random(0,255)), int(random(0,255)),int( random(0,255))));
  20.     pixels.show();
  21.     delay(2000);
  22.     pixels.setBrightness(0);
  23.     pixels.show();
  24.   
  25.   }
  26. }
复制代码
IMG_20210816_112133.jpg


IMG_20210816_112817.jpg


2、演示视频



【方向灯】

1、I2C LIS2DW12三轴加速度传感器

QQ截图20210816125228.jpg

LIS2DW12三轴加速度计是一款超低功耗的线性加速度计,该传感器拥有两个独立的可编程中断及专用内部引擎,可实现超多功能,例如自由落体检测、纵向/横向检测、朝向检测、可配置的单击/双击识别、运动检测、运动唤醒以实现高级省电等,我们为您提供了以上功能的示例程序,方便您在项目中轻松使用。 该传感器具有±2g /±4g /±8g /±16g的用户可选全刻度,并能够以1.6 Hz至1600 Hz的输出数据速率测量加速度,它内置多种带宽的多种运行模式,您可以按需选择合适的模式。

IMG_20210816_093510.jpg

IMG_20210816_093532.jpg



IMG_20210816_112714.jpg



  1. /**!
  2. * @file orientation.ino
  3. * @brief When detecting the orientation of the module, the sensor can detect the following six events:
  4. * @n Positive z-axis is facing up
  5. * @n Positive z-axis is facing down
  6. * @n Positive y-axis is facing up
  7. * @n Positive y-axis is facing down
  8. * @n Positive x-axis is facing up
  9. * @n Positive x-axis is facing down
  10. * @n When using SPI, chip select pin can be modified by changing the value of macro LIS2DW12_CS
  11. * @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
  12. * @licence     The MIT License (MIT)
  13. * @author [fengli](li.feng@dfrobot.com)
  14. * @version  V1.0
  15. * @date  2021-01-16
  16. * @get from https://www.dfrobot.com
  17. * @https://github.com/DFRobot/DFRobot_LIS
  18. */
  19. #include <DFRobot_LIS2DW12.h>
  20. #include <Adafruit_NeoPixel.h>
  21. #define PIN_LED 16     
  22. #define NUM_LED 1
  23.    
  24. Adafruit_NeoPixel pixels(NUM_LED, PIN_LED, NEO_GRB + NEO_KHZ800);
  25. //When using I2C communication, use the following program to construct an object by DFRobot_LIS2DW12_I2C
  26. /*!
  27. * @brief Constructor
  28. * @param pWire I2c controller
  29. * @param addr  I2C address(0x18/0x19)
  30. */
  31. DFRobot_LIS2DW12_I2C acce(&Wire,0x18);
  32. //DFRobot_LIS2DW12_I2C acce;
  33. //When using SPI communication, use the following program to construct an object by DFRobot_LIS2DW12_SPI
  34. #if defined(ESP32) || defined(ESP8266)
  35. #define LIS2DW12_CS  D3
  36. #elif defined(__AVR__) || defined(Arduino_SAM_ZERO)
  37. #define LIS2DW12_CS 3
  38. #elif (defined NRF5)
  39. #define LIS2DW12_CS 2  //The pin on the development board with the corresponding silkscreen printed as P2
  40. #endif
  41. /*!
  42. * @brief Constructor
  43. * @param cs Chip selection pinChip selection pin
  44. * @param spi SPI controller
  45. */
  46. //DFRobot_LIS2DW12_SPI acce(/*cs = */LIS2DW12_CS,&SPI);
  47. //DFRobot_LIS2DW12_SPI acce(/*cs = */LIS2DW12_CS);
  48. int lastOrientation = 0; //No event happened
  49. void setup(void){
  50.   pixels.begin();
  51.   Serial.begin(9600);
  52.   while(!acce.begin()){
  53.      Serial.println("Communication failed, check the connection and I2C address setting when using I2C communication.");
  54.      delay(1000);
  55.   }
  56.   Serial.print("chip id : ");
  57.   Serial.println(acce.getID(),HEX);
  58.   //Chip soft reset
  59.   acce.softReset();
  60.   
  61.   /**!
  62.     Set the sensor measurement range:
  63.                    e2_g   /<±2g>/
  64.                    e4_g   /<±4g>/
  65.                    e8_g   /<±8g>/
  66.                    e16_g  /< ±16g>/
  67.   */
  68.   acce.setRange(DFRobot_LIS2DW12::e2_g);
  69.   /**!
  70.    Set power mode:
  71.        eHighPerformance_14bit         /<High-Performance Mode,14-bit resolution>/
  72.        eContLowPwr4_14bit             /<Continuous measurement,Low-Power Mode 4(14-bit resolution)>/
  73.        eContLowPwr3_14bit             /<Continuous measurement,Low-Power Mode 3(14-bit resolution)>/
  74.        eContLowPwr2_14bit             /<Continuous measurement,Low-Power Mode 2(14-bit resolution)/
  75.        eContLowPwr1_12bit             /<Continuous measurement,Low-Power Mode 1(12-bit resolution)>/
  76.        eSingleLowPwr4_14bit           /<Single data conversion on demand mode,Low-Power Mode 4(14-bit resolution)>/
  77.        eSingleLowPwr3_14bit           /<Single data conversion on demand mode,Low-Power Mode 3(14-bit resolution)>/
  78.        eSingleLowPwr2_14bit           /<Single data conversion on demand mode,Low-Power Mode 2(14-bit resolution)>/
  79.        eSingleLowPwr1_12bit           /<Single data conversion on demand mode,Low-Power Mode 1(12-bit resolution)>/
  80.        eHighPerformanceLowNoise_14bit /<High-Performance Mode,Low-noise enabled,14-bit resolution>/
  81.        eContLowPwrLowNoise4_14bit     /<Continuous measurement,Low-Power Mode 4(14-bit resolution,Low-noise enabled)>/
  82.        eContLowPwrLowNoise3_14bit     /<Continuous measurement,Low-Power Mode 3(14-bit resolution,Low-noise enabled)>/
  83.        eContLowPwrLowNoise2_14bit     /<Continuous measurement,Low-Power Mode 2(14-bit resolution,Low-noise enabled)>/
  84.        eContLowPwrLowNoise1_12bit     /<Continuous measurement,Low-Power Mode 1(12-bit resolution,Low-noise enabled)>/
  85.        eSingleLowPwrLowNoise4_14bit   /<Single data conversion on demand mode,Low-Power Mode 4(14-bit resolution),Low-noise enabled>/
  86.        eSingleLowPwrLowNoise3_14bit   /<Single data conversion on demand mode,Low-Power Mode 3(14-bit resolution),Low-noise enabled>/
  87.        eSingleLowPwrLowNoise2_14bit   /<Single data conversion on demand mode,Low-Power Mode 2(14-bit resolution),Low-noise enabled>/
  88.        eSingleLowPwrLowNoise1_12bit   /<Single data conversion on demand mode,Low-Power Mode 1(12-bit resolution),Low-noise enabled>/
  89.   */
  90.   acce.setPowerMode(DFRobot_LIS2DW12::eContLowPwrLowNoise1_12bit);
  91.   
  92.   /**!
  93.     Set the sensor data collection rate:
  94.                eRate_0hz           /<Measurement off>/
  95.                eRate_1hz6          /<1.6hz, use only under low-power mode>/
  96.                eRate_12hz5         /<12.5hz>/
  97.                eRate_25hz         
  98.                eRate_50hz         
  99.                eRate_100hz         
  100.                eRate_200hz         
  101.                eRate_400hz       /<Use only under High-Performance mode>/
  102.                eRate_800hz       /<Use only under High-Performance mode>/
  103.                eRate_1k6hz       /<Use only under High-Performance mode>/
  104.                eSetSwTrig        /<The software triggers a single measurement>/
  105.   */
  106.   acce.setDataRate(DFRobot_LIS2DW12::eRate_200hz);
  107.   
  108.   /**!
  109.     Set the threshold of the angle when turning:
  110.                      eDegrees80   (80°)
  111.                      eDegrees70   (70°)
  112.                      eDegrees60   (60°)
  113.                      eDegrees50   (50°)
  114.   */
  115.   acce.set6DThreshold(DFRobot_LIS2DW12::eDegrees60);
  116.   
  117.   /**!
  118.     Set the interrupt source of the int1 pin:
  119.     eDoubleTap(Double click)
  120.     eFreeFall(Free fall)
  121.     eWakeUp(wake)
  122.     eSingleTap(single-Click)
  123.     e6D(Orientation change check)
  124.   */
  125.   acce.setInt1Event(DFRobot_LIS2DW12::e6D);
  126.   delay(1000);
  127. }
  128. void loop(void){
  129.     //check Changes detected in six directions
  130.     if(acce.oriChangeDetected()){
  131.         DFRobot_LIS2DW12::eOrient_t orientation = acce.getOrientation();
  132.         if(lastOrientation != orientation){
  133.             if(orientation == DFRobot_LIS2DW12::eXDown){
  134.              pixels.setPixelColor(0, pixels.Color(255,0,0));
  135.              pixels.show();
  136.             }
  137.             if(orientation == DFRobot_LIS2DW12::eXUp){
  138.              pixels.setPixelColor(0, pixels.Color(255,255,0));
  139.              pixels.show();
  140.             }
  141.             if(orientation == DFRobot_LIS2DW12::eYDown){
  142.              pixels.setPixelColor(0, pixels.Color(255,255,255));
  143.              pixels.show();
  144.             }
  145.             if(orientation == DFRobot_LIS2DW12::eYUp){
  146.              pixels.setPixelColor(0, pixels.Color(0,255,0));
  147.              pixels.show();
  148.             }
  149.             if(orientation == DFRobot_LIS2DW12::eZDown){
  150.              pixels.setPixelColor(0, pixels.Color(0,255,255));
  151.              pixels.show();
  152.             }
  153.             if(orientation == DFRobot_LIS2DW12::eZUp){
  154.              pixels.setPixelColor(0, pixels.Color(0,0,255));
  155.              pixels.show();
  156.             }
  157.             lastOrientation = orientation;
  158.         }
  159.     }
  160. }
复制代码


2、演示视频



天然闪队  见习技师

发表于 2021-8-16 17:26:37

老师,你这个扩展板在哪里买的?发个链接吧
回复

使用道具 举报

云天  高级技匠
 楼主|

发表于 2021-8-16 19:28:52

试用阶段,很快上市
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

为本项目制作心愿单
购买心愿单
心愿单 编辑
[[wsData.name]]

硬件清单

  • [[d.name]]
btnicon
我也要做!
点击进入购买页面
上海智位机器人股份有限公司 沪ICP备09038501号-4

© 2013-2022 Comsenz Inc. Powered by Discuz! X3.4 Licensed

mail