rtyu789 发表于 2024-10-22 23:05

【Follow me第二季第2期】基础任务

# 任务一:驱动12x8点阵LED

!(/data/attachment/forum/202410/22/230144rlne0lhpeizneldl.png.thumb.jpg?rand=5326.602703566113)
```C++
/*
Single Frame

Displays single frames using matrix.loadFrame

See the full documentation here:
https://docs.arduino.cc/tutorials/uno-r4-wifi/led-matrix
*/

#include "Arduino_LED_Matrix.h"   // Include the LED_Matrix library
#include "frames.h"               // Include a header file containing some custom icons

ArduinoLEDMatrix matrix;          // Create an instance of the ArduinoLEDMatrix class

void setup() {
Serial.begin(115200);         // Initialize serial communication at a baud rate of 115200
matrix.begin();               // Initialize the LED matrix
}

void loop() {
// Load and display the "chip" frame on the LED matrix
matrix.loadFrame(chip);
delay(500);// Pause for 500 milliseconds (half a second)

// Load and display the "danger" frame on the LED matrix
matrix.loadFrame(danger);
delay(500);

// Load and display the "happy" frame on the LED matrix
matrix.loadFrame(happy);
delay(500);

// Load and display the "big heart" frame provided by the library
matrix.loadFrame(LEDMATRIX_HEART_BIG);
delay(500);

// Turn off the display
matrix.clear();
delay(1000);

// Print the current value of millis() to the serial monitor
Serial.println(millis());
}
```
官方的例程中定义了chip,danger,happy,LEDMATRIX_HEART_BIG这几个图形,通过延时来切换图形显示
!(/data/attachment/forum/202410/22/230152jva69n19i47a5p9g.gif?rand=385.09205897547804)
# 任务二:用DAC生成正弦波

!(/data/attachment/forum/202410/22/230154eb0t9opg7djb0d7p.png.thumb.jpg?rand=9760.13954895486)
```C++
/*
SineWave

Generates a pre-generated sawtooth-waveform.

See the full documentation here:
https://docs.arduino.cc/tutorials/uno-r4-wifi/dac
*/

#include "analogWave.h" // Include the library for analog waveform generation

analogWave wave(DAC);   // Create an instance of the analogWave class, using the DAC pin

int freq = 10;// in hertz, change accordingly

void setup() {
Serial.begin(115200);// Initialize serial communication at a baud rate of 115200
wave.sine(freq);       // Generate a sine wave with the initial frequency
}

void loop() {
// Read an analog value from pin A5 and map it to a frequency range
freq = map(analogRead(A5), 0, 1024, 0, 10000);

// Print the updated frequency to the serial monitor
Serial.println("Frequency is now " + String(freq) + " hz");

wave.freq(freq);// Set the frequency of the waveform generator to the updated value
delay(1000);      // Delay for one second before repeating
}
```

通过A0口发出DAC信号,通过A5口接受,在Arduino IDE上显示
!(/data/attachment/forum/202410/22/230154arknbh5z2fwj89ko.jpg.thumb.jpg?rand=1524.4040964464123)

!(/data/attachment/forum/202410/22/230154dfyzfygeiyisdsk2.png.thumb.jpg?rand=2863.3041288188865)
# 任务三、四

用OPAMP放大DAC信号
用ADC采集并且打印数据到串口等其他接口可上传到上位机显示曲线
这两项由于没有示波器,所以就学习了一下代码

!(/data/attachment/forum/202410/22/230155bzfsqfi4hmsps55s.png.thumb.jpg?rand=8585.88899265519)

```C++
#include <OPAMP.h>

void setup () {
Serial.begin(9600);
delay(2000); // serial monitor delay
// activate OPAMP, default channel 0
// Plus: Analog A1
// Minus: Analog A2
// Output: Analog A3
if (!OPAMP.begin(OPAMP_SPEED_HIGHSPEED)) {
    Serial.println("Failed to start OPAMP!");
}
bool const isRunning = OPAMP.isRunning(0);
if (isRunning) {
    Serial.println("OPAMP running on channel 0!");
} else {
    Serial.println("OPAMP channel 0 is not running!");
}
}

void loop() {
delay(1000); // do nothing
}
```

# 参考资料
(https://docs.arduino.cc/tutorials/uno-r4-wifi/dac)
(https://docs.arduino.cc/hardware/uno-r4-wifi/)



Jacktang 发表于 2024-10-25 07:21

<p>DAC生成正弦波和OPAMP放大DAC信号,还好</p>
页: [1]
查看完整版本: 【Follow me第二季第2期】基础任务