/*********************************************************************
Certainly! To modify your code for a chasing LED effect using
Bluetooth control from your mobile device, follow these steps:
Add Bluetooth Module:
First, you’ll need to connect a Bluetooth module
(such as HC-05 or HC-06) to your Arduino.
Connect the TX and RX pins of the Bluetooth module to the corresponding pins on your Arduino (e.g., TX to Arduino RX, RX to Arduino TX).
Power the Bluetooth module using 3.3V or 5V
(check the module’s specifications).
Install a Bluetooth App on Your Mobile Device:
Install a Bluetooth terminal app on your mobile
phone (e.g., “Serial Bluetooth Terminal” for Android or “LightBlue Explorer” for iOS).
Pair your mobile device with the Bluetooth module.
Modify Your Code:
Add the necessary Bluetooth communication code to your existing sketch. We’ll use the Bluetooth module to receive commands from your mobile device.
Here’s an updated version of your code:
Control LEDs via Bluetooth:
Open the Bluetooth terminal app on your mobile device.
Pair with your Bluetooth module.
Send the following commands:
‘1’ to activate the chasing effect (LEDs turning on one by one).
‘2’ to deactivate the effect (LEDs turning off one by one).
Upload the Modified Code:
Upload the modified code to your Arduino board.
Test:
Turn on your Arduino and ensure that the Bluetooth module
is connected.
Use the Bluetooth terminal app to control the LEDs.
Remember to adjust the baud rate in the Serial.begin(9600)
line to match the configuration of your Bluetooth module.
Enjoy your Bluetooth-controlled chasing
LEDs! 🚀🔵
*************************************/
#include <Arduino.h>
// Define the number of LEDs
const int num_leds = 10;
// Define the LED pins
const int led_pins[] = { 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
void setup() {
// Initialize LED pins as outputs
for (int i = 0; i < num_leds; ++i) {
pinMode(led_pins[i], OUTPUT);
}
// Initialize serial communication for Bluetooth
Serial.begin(9600); // Set the baud rate to match your Bluetooth module
}
void loop() {
while (true) {
// Check for incoming Bluetooth commands
if (Serial.available()) {
char command = Serial.read();
if (command == '1') {
// Turn on LEDs one by one in sequence
for (int i = 0; i < num_leds; ++i) {
digitalWrite(led_pins[i], HIGH);
delay(100); // Adjust the delay as needed
digitalWrite(led_pins[i], LOW);
}
} else if (command == '2') {
// Turn off LEDs one by one in reverse sequence
for (int i = num_leds - 1; i >= 0; --i) {
digitalWrite(led_pins[i], HIGH);
delay(100); // Adjust the delay as needed
digitalWrite(led_pins[i], LOW);
}
}
}
}
}