2025年9月30日火曜日

UNO R4 TUTORIAL 4(RTC,BLE2,HC-SR,LEDstrip)

 https://docs.sunfounder.com/projects/elite-explorer-kit/ja/latest/new_feature_projects/03_rtc.html はTIME SETして時間ごとに仕事する

残念ながら、TIME取得の方法がなかった

https://garretlab.web.fc2.com/arduino.cc/docs/tutorials/uno-r4-wifi/rtc/  にあった

----------------------------------------------------------------

https://docs.sunfounder.com/projects/elite-explorer-kit/ja/latest/iot_projects/07_iot_ble_lcd.html に成功

LIGHT BLUEでは、READ,WRITEをタップして、WRITEにすすみHEXバーをタップして

UTF8にフォーマット変更する!(saveボタンで)

------------------------------------------------------------------------------

HC-SR04 ultrasonic distance meter:: LCDをつながないときは操作部分をコメントアウト!

そうでないと動かんみたいだ、これ案外重要かも


#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 16, 2); // initialize the Liquid Crystal Display object with the I2C address 0x27, 16 columns and 2 rows

// Define the pin numbers for the ultrasonic sensor
const int echoPin = 3;
const int trigPin = 4;

void setup() {
Serial.begin(9600);
while(!Serial);
Serial.println("start");
pinMode(echoPin, INPUT); // Set echo pin as input
pinMode(trigPin, OUTPUT); // Set trig pin as output

//lcd.init(); // initialize the LCD
//lcd.clear(); // clear the LCD display
//lcd.backlight(); // Make sure backlight is on
}

void loop() {
float distance = readDistance(); // Call the function to read the sensor data and get the distance

//lcd.setCursor(0, 0); //Place the cursor at Line 1, Column 1. From here the characters are to be displayed
//lcd.print("Distance:"); ////Print Distance: on the LCD
//lcd.setCursor(0, 1); //Set the cursor at Line 1, Column 0
//lcd.print(" "); //Here is to leave some spaces after the characters so as to clear the previous characters that may still remain.
//lcd.setCursor(7, 1); //Set the cursor at Line 1, Column 7.
//lcd.print(distance); // print on the LCD the value of the distance converted from the time between ping sending and receiving.
//lcd.setCursor(14, 1); //Set the cursor at Line 1, Column 14.
// lcd.print("cm"); //print the unit "cm"
Serial.println(distance);
delay(800); // Delay for 800 milliseconds before repeating the loop
}

// Function to read the sensor data and calculate the distance
float readDistance() {
digitalWrite(trigPin, LOW); // Set trig pin to low to ensure a clean pulse
delayMicroseconds(2); // Delay for 2 microseconds
digitalWrite(trigPin, HIGH); // Send a 10 microsecond pulse by setting trig pin to high
delayMicroseconds(10);
digitalWrite(trigPin, LOW); // Set trig pin back to low

// Measure the pulse width of the echo pin and calculate the distance value
float distance = pulseIn(echoPin, HIGH) / 58.00; // Formula: (340m/s * 1us) / 2
return distance;
}
---------------------------------------------------------------------
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); is a FastLED library function that configures the LED strip

0 件のコメント:

コメントを投稿