diff --git a/UNO_R4_MINIMA/docs/1.Minima-Tutorial Documentation.pdf b/UNO_R4_MINIMA/docs/1.Minima-Tutorial Documentation.pdf new file mode 100644 index 0000000..a81ea8e Binary files /dev/null and b/UNO_R4_MINIMA/docs/1.Minima-Tutorial Documentation.pdf differ diff --git a/UNO_R4_MINIMA/example/Lesson_10_Photoresistor/Lesson_10_Photoresistor.ino b/UNO_R4_MINIMA/example/Lesson_10_Photoresistor/Lesson_10_Photoresistor.ino new file mode 100644 index 0000000..ab12bf8 --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_10_Photoresistor/Lesson_10_Photoresistor.ino @@ -0,0 +1,15 @@ +//2024.3.5 +const int analogInPin = A1; //光敏电阻模拟输入引脚 The photoresistor mimics the input pin +int Lightvalue = 0; //定义变量 Defining variables + +void setup() { + Serial.begin(9600); //初始化串口波特率 Initialize the serial port baud rate + pinMode(analogInPin,INPUT); +} + +void loop() { + Lightvalue = analogRead(analogInPin); //读取光敏度的值 Read the value of light sensitivity + Serial.print("Lightvalue = "); //通过串口打印光敏度的值 Print the value of light sensitivity through the serial port + Serial.println(Lightvalue); + delay(200); +} diff --git a/UNO_R4_MINIMA/example/Lesson_11_Ultrasonic_ranging_OLED_display/Lesson_11_Ultrasonic_ranging_OLED_display.ino b/UNO_R4_MINIMA/example/Lesson_11_Ultrasonic_ranging_OLED_display/Lesson_11_Ultrasonic_ranging_OLED_display.ino new file mode 100644 index 0000000..e9e665f --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_11_Ultrasonic_ranging_OLED_display/Lesson_11_Ultrasonic_ranging_OLED_display.ino @@ -0,0 +1,58 @@ +#include +#include +#include + +#define SCREEN_WIDTH 128 // 定义屏幕宽度为128像素 Define the screen width to be 128 pixels +#define SCREEN_HEIGHT 64 // 定义屏幕高度为64像素 Define the screen height to be 64 pixels +#define OLED_RESET -1 // 定义 OLED 复位引脚为-1(如果不使用复位功能,则设置为-1) Define the OLED reset pin to -1 (or -1 if the reset function is not used) +// 创建 Adafruit_SSD1306 对象,用于控制 OLED 屏幕,指定屏幕宽度、高度、I2C 总线对象和复位引脚 +// Create an Adafruit_SSD1306 object that controls the OLED screen, specifying the screen width, height, I2C bus object, and reset pin +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +#define Echo 6 //定义超声波Echo引脚 Define the ultrasonic Echo pin +#define Trig 5 //定义超声波Trig引脚 Define the ultrasonic Trig pin +int Udistance = 0; //定义超声波距离变量 Define the ultrasonic distance variable + +void setup() { + Serial.begin(9600); + pinMode(Echo, INPUT); //定义引脚工作模式为输入 Define the pin operation mode as the input + pinMode(Trig, OUTPUT); //定义引脚工作模式为输出 Define the pin operation mode as output + Wire.begin(); //初始化 I2C 总线 SDA引脚设置为A4,SCL引脚设置为A5 The initial I2C bus SDA pin is set to A4 and the SCL pin is set to A5 + + // 初始化屏幕 Initializing the screen + if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { + Serial.println(F("SSD1306 initialization failed")); + for (;;) + ; + } +} + +void loop() { + Udistance = GetDistance(); // 获取超声波距离 Obtaining ultrasonic distance + display.clearDisplay(); // 清空屏幕缓冲区 Clear the screen buffer + //显示超声波距离 Display ultrasonic distance + display.setTextSize(2); + display.setTextColor(SSD1306_WHITE); + display.setCursor(16, 8); + display.println("Distance"); + display.setCursor(32, 40); + display.print(Udistance); + display.print(" cm"); + display.display(); + //delay(200); // 延迟一段时间再进行下一次读取 Delay the next read for a while to adjust the update rate + //Serial.print("Distance = "); + //Serial.println(Udistance); +} + +float GetDistance() //获取超声波传感器数值 Get ultrasonic sensor values +{ + float distance; + digitalWrite(Trig, LOW); //发送一个低电平到Trig触发测距 Sending a low level to the Trig triggers ranging + delayMicroseconds(2); + digitalWrite(Trig, HIGH); + delayMicroseconds(10); + digitalWrite(Trig, LOW); + distance = pulseIn(Echo, HIGH) / 58.00; //输出距离转换 Output distance conversion + //delay(10); + return distance; +} \ No newline at end of file diff --git a/UNO_R4_MINIMA/example/Lesson_12_DHT11_OLED_display/Lesson_12_DHT11_OLED_display.ino b/UNO_R4_MINIMA/example/Lesson_12_DHT11_OLED_display/Lesson_12_DHT11_OLED_display.ino new file mode 100644 index 0000000..284fbbb --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_12_DHT11_OLED_display/Lesson_12_DHT11_OLED_display.ino @@ -0,0 +1,48 @@ +#include +#include +#include +#include + +#define SCREEN_WIDTH 128 // 定义屏幕宽度为128像素 Define the screen width to be 128 pixels +#define SCREEN_HEIGHT 64 // 定义屏幕高度为64像素 Define the screen height to be 64 pixels +#define OLED_RESET -1 // 定义 OLED 复位引脚为-1(如果不使用复位功能,则设置为-1) Define the OLED reset pin to -1 (or -1 if the reset function is not used) +// 创建 Adafruit_SSD1306 对象,用于控制 OLED 屏幕,指定屏幕宽度、高度、I2C 总线对象和复位引脚 +// Create an Adafruit_SSD1306 object that controls the OLED screen, specifying the screen width, height, I2C bus object, and reset pin +Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); + +#define DHTPIN 4 // DHT11传感器连接到Arduino的数字引脚4 The DHT11 sensor is connected to digital pin 4 of the Arduino +#define DHTTYPE DHT11 // 使用DHT11传感器 The DHT11 sensor was used +DHT dht(DHTPIN, DHTTYPE); // 创建 DHT 对象,用于连接 DHT 传感器,指定传感器引脚和传感器型号 Create DHT objects for connecting DHT sensors, specifying sensor pins and sensor models + +void setup() { + Serial.begin(9600); + Wire.begin(); //初始化 I2C 总线 SDA引脚设置为A4,SCL引脚设置为A5 The initial I2C bus SDA pin is set to A4 and the SCL pin is set to A5 + + // 初始化 OLED 屏幕 Initializing the screen + if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { + Serial.println(F("SSD1306 initialization failed")); + for (;;) + ; + } + display.clearDisplay(); // 清空屏幕缓冲区 Clear the screen buffer + dht.begin(); // 初始化 DHT11 传感器 Initialize the DHT11 sensor +} + +void loop() { + // 读取温湿度数据 Read the temperature and humidity data + int humidity = dht.readHumidity(); + int temperature = dht.readTemperature(); + display.clearDisplay();// 清空屏幕缓冲区 Clear the screen buffer + // 显示温湿度数据 Display temperature and humidity data + display.setTextSize(1); + display.setTextColor(SSD1306_WHITE); + display.setCursor(16, 20); + display.print("Temperature: "); + display.println(temperature); + display.setCursor(16, 40); + display.print("Humidity: "); + display.print(humidity); + display.println("%"); + display.display();// 更新显示 + delay(2000); // 延迟2秒再进行下一次读取 +} diff --git a/UNO_R4_MINIMA/example/Lesson_13_Infrared_change_RGB/Lesson_13_Infrared_change_RGB.ino b/UNO_R4_MINIMA/example/Lesson_13_Infrared_change_RGB/Lesson_13_Infrared_change_RGB.ino new file mode 100644 index 0000000..5c87a04 --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_13_Infrared_change_RGB/Lesson_13_Infrared_change_RGB.ino @@ -0,0 +1,54 @@ +#include +#include + +//设定三个按键的红外信号值 Set the infrared signal value of the three keys +#define NUM1 0xF30CFF00 //number 1 +#define NUM2 0xE718FF00 //number 2 +#define NUM3 0xA15EFF00 //number 3 +#define IR_RECEIVE_PIN A2 //定义红外接收器的引脚 Define the pins of the infrared receiver + +#define LED_PIN 7 //定义WS2812B RGB灯引脚 Define the WS2812B RGB lamp pin +#define NUM_LEDS 12 //定义灯珠数量 Define the number of beads +#define BRIGHTNESS 5 //定义灯光亮度 Defining the brightness of the light +#define FRAMES_PER_SECOND 120 //定义每秒帧数 Defines frames per second +CRGB leds[NUM_LEDS]; //定义一个长度为 NUM_LEDS 的 CRGB 类型数组,用于控制 WS2812B LED 条 A CRGB type array of length NUM_LEDS is defined to control WS2812B LED strips +static uint8_t hue = 0; //设置颜色的值 Sets the value of the color +int Color = 1; //定义灯光颜色模式的变量 A variable that defines the color pattern of the light + +void setup() { + Serial.begin(9600); + IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); //启用红外接收功能 Enable infrared receiver function + FastLED.addLeds(leds, NUM_LEDS); //使用FastLED库将LED条上的LED添加到控制器中 The LED on the LED strip is added to the controller using the FastLED library + FastLED.setBrightness(BRIGHTNESS); //设置灯光亮度 Set the light brightness + pinMode(LED_PIN, OUTPUT); //定义7引脚为输出模式 Pin 7 is defined as the output mode + digitalWrite(LED_PIN, LOW); //设定7引脚为低电平输出 Set pin 7 for low output +} + +void loop() { + if (IrReceiver.decode()) { + // Serial.println(IrReceiver.decodedIRData.decodedRawData, HEX); //打印“旧的”原始数据 Print the "old" raw data + // IrReceiver.printIRResultShort(&Serial); //在一行中打印完整的接收数据 Print the complete received data on one line + // IrReceiver.printIRSendUsage(&Serial); //打印发送此数据所需的语句 Print the statements needed to send this data + if (IrReceiver.decodedIRData.decodedRawData == NUM1) { + Color = 1; //如果按下按键1,颜色模式为红 If key 1 is pressed, the color mode is red + } else if (IrReceiver.decodedIRData.decodedRawData == NUM2) { + Color = 2; //如果按下按键2,颜色模式为绿 If key 1 is pressed, the color mode is green + } else if (IrReceiver.decodedIRData.decodedRawData == NUM3) { + Color = 3; //如果按下按键3,颜色模式为蓝 If key 1 is pressed, the color mode is blue + } + IrReceiver.resume(); // 等下接收下一个值 Wait to receive the next value + } + + for (int i = 0; i < NUM_LEDS; i++) { + // 根据颜色值设置LED的颜色 + if (Color == 1) { + leds[i] = CHSV(hue, 255, 255); // 设置为红色 set it to red + } else if (Color == 2) { + leds[i] = CHSV(hue + 85, 255, 255); // 设置为绿色 set it to green + } else if (Color == 3) { + leds[i] = CHSV(hue + 170, 255, 255); // 设置为蓝色 set it to blue + } + FastLED.show();// 显示LED的颜色 Displays the color of the LED + FastLED.delay(2 / FRAMES_PER_SECOND);// 延迟以控制帧率 Delay to control the frame rate + } +} diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/0_Arduino software/Arduino IDE Download Link.txt b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/0_Arduino software/Arduino IDE Download Link.txt new file mode 100644 index 0000000..4c3d250 --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/0_Arduino software/Arduino IDE Download Link.txt @@ -0,0 +1 @@ +https://www.arduino.cc/en/software \ No newline at end of file diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_BusIO.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_BusIO.zip new file mode 100644 index 0000000..54f09dd Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_BusIO.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_GFX_Library.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_GFX_Library.zip new file mode 100644 index 0000000..d178c25 Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_GFX_Library.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_SSD1306.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_SSD1306.zip new file mode 100644 index 0000000..f79d7a5 Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_SSD1306.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_Unified_Sensor.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_Unified_Sensor.zip new file mode 100644 index 0000000..68a315a Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Adafruit_Unified_Sensor.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/AsyncTCP.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/AsyncTCP.zip new file mode 100644 index 0000000..f0d12ba Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/AsyncTCP.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/DHT_sensor_library.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/DHT_sensor_library.zip new file mode 100644 index 0000000..acf65c8 Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/DHT_sensor_library.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/ESP32Servo.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/ESP32Servo.zip new file mode 100644 index 0000000..0b58fd9 Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/ESP32Servo.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/ESPAsyncWebServer.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/ESPAsyncWebServer.zip new file mode 100644 index 0000000..5fa6fcb Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/ESPAsyncWebServer.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/FastLED.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/FastLED.zip new file mode 100644 index 0000000..cb455aa Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/FastLED.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/IRremote.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/IRremote.zip new file mode 100644 index 0000000..cf926fb Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/IRremote.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/IRremoteESP8266.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/IRremoteESP8266.zip new file mode 100644 index 0000000..918d568 Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/IRremoteESP8266.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Servo.zip b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Servo.zip new file mode 100644 index 0000000..abd0daf Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/1_Libraries/Servo.zip differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/CH340 Driver File-MAC/CH34X_DRV_INSTALL_INSTRUCTIONS.pdf b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/CH340 Driver File-MAC/CH34X_DRV_INSTALL_INSTRUCTIONS.pdf new file mode 100644 index 0000000..1fc4d1c Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/CH340 Driver File-MAC/CH34X_DRV_INSTALL_INSTRUCTIONS.pdf differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/CH340 Driver File-MAC/CH34xVCPDriver.pkg b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/CH340 Driver File-MAC/CH34xVCPDriver.pkg new file mode 100644 index 0000000..f709709 Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/CH340 Driver File-MAC/CH34xVCPDriver.pkg differ diff --git a/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/FAQ-EN.pdf b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/FAQ-EN.pdf new file mode 100644 index 0000000..86df808 Binary files /dev/null and b/UNO_R4_MINIMA/example/Lesson_1_Arduino IDE/2_CH340 Driver/FAQ-EN.pdf differ diff --git a/UNO_R4_MINIMA/example/Lesson_2_Light_up_the_LED/Lesson_2_Light_up_the_LED.ino b/UNO_R4_MINIMA/example/Lesson_2_Light_up_the_LED/Lesson_2_Light_up_the_LED.ino new file mode 100644 index 0000000..53b2871 --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_2_Light_up_the_LED/Lesson_2_Light_up_the_LED.ino @@ -0,0 +1,20 @@ +/* + Lesson_2_Light_up_the_LED + + 点亮L灯 Light the L lamp + + Connect the motherboard to the computer using the Type-C line, + complete the code upload, and observe the L light on the motherboard. + +*/ + +#define LED 12 //定义LED灯输出引脚 Define the LED lamp output pin +void setup() { + pinMode(LED, OUTPUT); //定义引脚的工作模式 Define the operation mode of the pin + digitalWrite(LED, LOW); //输出低电平 Output low level +} + +void loop() { + //因为LED灯负极已经连接到GND,只需要输出高电平即可运行点亮LED灯 The output high level can be run to light the LED lamp + digitalWrite(LED, HIGH); +} diff --git a/UNO_R4_MINIMA/example/Lesson_3_Button_control_LED/Lesson_3_Button_control_LED.ino b/UNO_R4_MINIMA/example/Lesson_3_Button_control_LED/Lesson_3_Button_control_LED.ino new file mode 100644 index 0000000..7f7ee6c --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_3_Button_control_LED/Lesson_3_Button_control_LED.ino @@ -0,0 +1,29 @@ +//2024.3.5 +#define LED 12 //定义LED2引脚 +#define button 9 //定义按键信号引脚 +int key_ok = 0; //定义项目所需的数据变量 +int LED_en = 0; +void setup() { + Serial.begin(9600); + pinMode(button, INPUT); //设置按键引脚为输入 + pinMode(LED, OUTPUT); //设置按键引脚为输入 +} + +void loop() { + // 判断是否有按钮被按下,读取按钮的电平 + if (digitalRead(button)) { + if (key_ok) //判断按钮是否被按下 + { + key_ok = 0; + if (LED_en) LED_en = 0; //确定最后一个标志位是否建立 + else LED_en = 1; + } + } else { + delay(20); //延时20毫秒 + if (!digitalRead(button)) key_ok = 1; + } + + //当按下按键时,LED灯输出引脚的电平反转 + if (LED_en) digitalWrite(LED, HIGH); + else digitalWrite(LED, LOW); +} diff --git a/UNO_R4_MINIMA/example/Lesson_4_active_buzzer/Lesson_4_active_buzzer.ino b/UNO_R4_MINIMA/example/Lesson_4_active_buzzer/Lesson_4_active_buzzer.ino new file mode 100644 index 0000000..191a726 --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_4_active_buzzer/Lesson_4_active_buzzer.ino @@ -0,0 +1,12 @@ +//2024.3.5 +#define Buzzer 8 //定义有源蜂鸣器引脚 Define the active buzzer pin +void setup() { + pinMode(Buzzer, OUTPUT); //定义引脚为输出工作模式 Define the pin as the output working mode +} + +void loop() { + digitalWrite(Buzzer, HIGH); //输出高电平,蜂鸣器响 Output high level, buzzer goes off + delay(500); + digitalWrite(Buzzer, LOW); //输出低电平,蜂鸣器不响 The output is low and the buzzer does not sound + delay(500); +} diff --git a/UNO_R4_MINIMA/example/Lesson_5_Traffic_light/Lesson_5_Traffic_light.ino b/UNO_R4_MINIMA/example/Lesson_5_Traffic_light/Lesson_5_Traffic_light.ino new file mode 100644 index 0000000..c92479d --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_5_Traffic_light/Lesson_5_Traffic_light.ino @@ -0,0 +1,55 @@ +//2024.3.6 + +#define Green 12 //定义绿色灯引脚 Define the green light pin +#define Yellow 11 //定义黄色灯引脚 Define the yellow light pin +#define red 10 //定义绿色灯引脚 Define the green light pin + +void setup() { + // 定义引脚为输出工作模式 Define the pin as the output working mode + pinMode(Green, OUTPUT); + pinMode(Yellow, OUTPUT); + pinMode(red, OUTPUT); +} + +void loop() { + digitalWrite(Green, HIGH); //点亮绿色灯 Turn on the green light + digitalWrite(Yellow, LOW); //熄灭黄色灯 Put out the yellow light + digitalWrite(red, LOW); //熄灭红色灯 Turn off the red light + delay(5000); //让绿灯亮五秒钟 Turn on the green light for five seconds + + //绿灯每500毫秒闪烁一次 The green light flashes every 500 milliseconds + digitalWrite(Green, HIGH); + delay(500); + digitalWrite(Green, LOW); + delay(500); + digitalWrite(Green, HIGH); + delay(500); + digitalWrite(Green, LOW); + delay(500); + digitalWrite(Green, HIGH); + delay(500); + + //黄灯亮1秒 The yellow light is on for 1 second + digitalWrite(Green, LOW); + digitalWrite(Yellow, HIGH); + digitalWrite(red, LOW); + delay(1200); + + //红灯亮5秒钟 The red light stays on for 5 seconds + digitalWrite(Green, LOW); + digitalWrite(Yellow, LOW); + digitalWrite(red, HIGH); + delay(5000); + + //红灯每500毫秒闪烁一次 The red light flashes every 500 milliseconds + digitalWrite(red, HIGH); + delay(500); + digitalWrite(red, LOW); + delay(500); + digitalWrite(red, HIGH); + delay(500); + digitalWrite(red, LOW); + delay(500); + digitalWrite(red, HIGH); + delay(500); +} diff --git a/UNO_R4_MINIMA/example/Lesson_6_Flow_light/Lesson_6_Flow_light.ino b/UNO_R4_MINIMA/example/Lesson_6_Flow_light/Lesson_6_Flow_light.ino new file mode 100644 index 0000000..c25a1d2 --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_6_Flow_light/Lesson_6_Flow_light.ino @@ -0,0 +1,28 @@ +//2024.3.6 + +#define Green 12 //定义绿色灯引脚 +#define Yellow 11 //定义黄色灯引脚 +#define red 10 //定义绿色灯引脚 +void setup() { + //定义引脚为输出工作模式 + pinMode(Green, OUTPUT); //绿色灯 + pinMode(Yellow, OUTPUT); //黄色灯 + pinMode(red, OUTPUT); //红色灯 +} + +void loop() { + digitalWrite(Green, HIGH); //点亮绿色灯 + digitalWrite(Yellow, LOW); //熄灭黄色灯 + digitalWrite(red, LOW); //熄灭红色灯 + delay(200); //让绿灯亮200毫秒 + + digitalWrite(Green, LOW); //熄灭绿色灯 + digitalWrite(Yellow, HIGH); //点亮黄色灯 + digitalWrite(red, LOW); //熄灭红色灯 + delay(200); //让黄灯亮200毫秒 + + digitalWrite(Green, LOW); //熄灭绿色灯 + digitalWrite(Yellow, LOW); //熄灭黄色灯 + digitalWrite(red, HIGH); //点亮红色灯 + delay(200); //让红灯亮200毫秒 +} diff --git a/UNO_R4_MINIMA/example/Lesson_7_WS2812B/Lesson_7_WS2812B.ino b/UNO_R4_MINIMA/example/Lesson_7_WS2812B/Lesson_7_WS2812B.ino new file mode 100644 index 0000000..669a5e6 --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_7_WS2812B/Lesson_7_WS2812B.ino @@ -0,0 +1,20 @@ +#include //声明FastLED库 Declare the FastLED library + +#define LED_PIN 7 //定义WS2812 RGB灯引脚 Define the WS2812 RGB lamp pin +#define NUM_LEDS 12 //定义灯珠数量 Define the number of beads +#define BRIGHTNESS 64 //设定灯光亮度,范围0~255,数字越大越亮 Set the light level from 0 to 255, with the higher the light +CRGB leds[NUM_LEDS]; //实例化一个长度为 NUM_LEDS 的 CRGB 类型数组,用于控制WS2812B LED灯条 An array of CRGB type with length NUM_LEDS is instantiated to control the WS2812B LED strip +void setup() { + FastLED.addLeds(leds, NUM_LEDS); //使用NEOPIXEL类型 Use the NEOPIXEL type + FastLED.setBrightness(BRIGHTNESS); //初始化灯光亮度 Initialize the light level +} + +void loop() { + //逐个点亮LED显示绿色 Light the leds one by one to show green + for (int i = 0; i < NUM_LEDS; i++) { + fill_solid(leds, NUM_LEDS, CRGB::Black); //将所有LED关闭 Turn off all leds + leds[i] = CRGB::Green; //仅点亮当前LED Light only the current LED + FastLED.show(); + delay(100); + } +} diff --git a/UNO_R4_MINIMA/example/Lesson_8_Gradient_RGB_light/Lesson_8_Gradient_RGB_light.ino b/UNO_R4_MINIMA/example/Lesson_8_Gradient_RGB_light/Lesson_8_Gradient_RGB_light.ino new file mode 100644 index 0000000..4ea70cd --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_8_Gradient_RGB_light/Lesson_8_Gradient_RGB_light.ino @@ -0,0 +1,21 @@ +//2024.3.6 +#include + +#define LED_PIN 7 //定义WS2812 RGB灯引脚 +#define NUM_LEDS 12 //定义灯珠数量 +#define BRIGHTNESS 64 //设定灯光亮度,范围0~255,数字越大越亮 +CRGB leds[NUM_LEDS]; //定义一个长度为 NUM_LEDS 的 CRGB 类型数组,用于控制 WS2812B LED 条 + +void setup() { + FastLED.addLeds(leds, NUM_LEDS); //使用NEOPIXEL类型 + FastLED.setBrightness(BRIGHTNESS); //初始化灯光亮度 +} + +void loop() { + //渐变显示不同颜色 Gradients display different colors + for (int hue = 0; hue < 255; hue++) { + fill_rainbow(leds, NUM_LEDS, hue, 8); + FastLED.show(); + delay(20); + } +} diff --git a/UNO_R4_MINIMA/example/Lesson_9_Steering_gear_control/Lesson_9_Steering_gear_control.ino b/UNO_R4_MINIMA/example/Lesson_9_Steering_gear_control/Lesson_9_Steering_gear_control.ino new file mode 100644 index 0000000..89e3105 --- /dev/null +++ b/UNO_R4_MINIMA/example/Lesson_9_Steering_gear_control/Lesson_9_Steering_gear_control.ino @@ -0,0 +1,23 @@ +#include +#define SERVO_PIN A0 //将舵机信号线连接到UNOR4 MINIMA的A0 Connect the servo signal line to A0 of UNOR4 MINIMA +Servo myServo; //实例化一个舵机对象 Instantiate a steering gear object + +void setup() { + pinMode(SERVO_PIN, OUTPUT); //将舵机连接的引脚设为输出模式 Set the servo connected pin to output mode + myServo.attach(SERVO_PIN); //设置舵机对象 Set the steering gear object +} + +void loop() { + //让舵机从180度转到0度 Let the steering gear turn from 180 to 0 degrees + for (int angle = 180; angle >= 0; angle--) { + myServo.write(angle); + delay(5); + } + + //让舵机从0度转到180度 Let the steering gear turn from 0 to 180 degrees + for (int angle = 0; angle <= 180; angle++) { + myServo.write(angle); + delay(5); //等待一小段时间,使舵机有足够的时间运动到下一个角度 + } + +}