asdxz7

  • 2025-01-16
  • 发表了主题帖: 【Follow me第二季第4期】-任务提交与汇总

    任务一:搭建环境并开启第一步Blink三色LED / 串口打印Hello DigiKey & EEWorld!; 基本思路:1.LED点亮与呼吸灯:对LEDR、LEDG、LEDB进行PWM写入                   2.串口输出:设置波特率并且打印Hello DigiKey & EEWorld! 以下是代码: #include "WiFiNINA.h" #define Led1 LEDR #define Led2 LEDG #define Led3 LEDB float angle1; float angle2; float angle3; void setup() { // put your setup code here, to run once: pinMode(Led1, OUTPUT); pinMode(Led2, OUTPUT); pinMode(Led3, OUTPUT); for(int i =0; i < 5 ; i++) { digitalWrite(Led1, LOW); digitalWrite(Led2, HIGH); delay(200); digitalWrite(Led2, LOW); digitalWrite(Led3, HIGH); delay(200); digitalWrite(Led3, LOW); digitalWrite(Led1, HIGH); delay(200); } angle1 = 0.0; angle2 = 0.0 + PI /3.0; angle3 = 0.0 + 2.0 * PI /3.0; Serial.begin(115200); } void loop() { // put your main code here, to run repeatedly: Serial.println("Hello Digikey & EEWorld"); angle1 += 0.01; angle2 += 0.01; angle3 += 0.01; if(angle1 >= PI) angle1 -= PI; if(angle2 >= PI) angle2 -= PI; if(angle3 >= PI) angle3 -= PI; int a = sin (angle1) * 255; int b = sin (angle2) * 255; int c = sin (angle3) * 255; analogWrite(Led1 ,a); analogWrite(Led2 ,b); analogWrite(Led3 ,c); delay(50); }     任务二:学习IMU基础知识,调试IMU传感器,通过串口打印六轴原始数据; 1.初始化陀螺仪采样频率 2.采集数据 3.打印数据到串口 以下是代码: #include <Arduino_LSM6DSOX.h> float acc_x,acc_y,acc_z; float gyro_x,gyro_y,gyro_z; float temp; int update_flag; void setup() { // put your setup code here, to run once: Serial.begin(115200); if(!IMU.begin()) { Serial.println("Falled to initialize IMU"); while(1); } Serial.print("Acc sample rate = "); Serial.print(IMU.accelerationSampleRate()); Serial.println("Hz"); Serial.print("Gyro sample rate = "); Serial.print(IMU.gyroscopeSampleRate()); Serial.println("Hz"); } void loop() { // put your main code here, to run repeatedly: Serial.print("Acc sample rate = "); Serial.print(IMU.accelerationSampleRate()); Serial.println("Hz"); Serial.print("Gyro sample rate = "); Serial.print(IMU.gyroscopeSampleRate()); Serial.println("Hz"); if (IMU.accelerationAvailable()) { IMU.readAcceleration(acc_x,acc_y,acc_z); update_flag = 1; } if (IMU.gyroscopeAvailable()) { IMU.readGyroscope(gyro_x,gyro_y,gyro_z); update_flag = 1; } if (IMU.temperatureAvailable()) { IMU.readTemperatureFloat(temp); update_flag = 1; } if (update_flag) { update_flag=0; Serial.print(acc_x); Serial.print(','); Serial.print(acc_y); Serial.print(','); Serial.print(acc_z); Serial.print(','); Serial.print(gyro_x); Serial.print(','); Serial.print(gyro_y); Serial.print(','); Serial.print(gyro_z); Serial.print(','); Serial.print(gyro_x); Serial.print(','); Serial.println(temp); delay(500); } }     任务三:学习PDM麦克风技术知识,调试PDM麦克风,通过串口打印收音数据和音频波形。 思路: 1.初始化麦克风(采样率)以及波特率 2.采集数据 3.串口打印数据   代码: #include "PDM.h" static const char channels = 1; static const int frequncy = 24000; short sampleBuffer[512]; volatile int samplesRead; void setup() { // put your setup code here, to run once: Serial.begin(115200); PDM.onReceive(onPDMdata); if(!PDM.begin(channels,frequncy)) { Serial.println("Failed to start PDM!!!"); while(1); } } void loop() { // put your main code here, to run repeatedly: if(samplesRead) { for(int i = 0; i < samplesRead; i++) { Serial.println(sampleBuffer[i]); } samplesRead=0; } delay(1); } void onPDMdata(){ int bytesAvailable = PDM.available(); PDM.read(sampleBuffer,bytesAvailable); samplesRead = bytesAvailable / 2; }  

  • 加入了学习《直播回放: DigiKey FollowMe 第二季 第4期 Arduino Nano RP2040 Connect 任务讲解》,观看 Arduino Nano RP2040 Connect 任务讲解

最近访客

< 1/1 >

统计信息

已有1人来访过

  • 芯积分:19
  • 好友:--
  • 主题:1
  • 回复:0

留言

你需要登录后才可以留言 登录 | 注册


现在还没有留言