#include <FastLED.h>
#define NUM_LEDS 64
CRGB leds[NUM_LEDS];
// defines pins numbers
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
int color = 255;
int color2 = 0;
int sound = 0;
void setup() {
FastLED.addLeds<NEOPIXEL, 8>;(leds, NUM_LEDS);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(9600); // Starts the serial communication
}
void loop()
{
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
color = map(distance, 13, 0, 255, 0);
color2 = map(distance, 13, 0, 0, 255);
sound = map(distance, 13, 0, 200, 5000);
tone(11, sound, 100);
for(int i=0; i < 64; i++)
{
leds[i].setRGB( color, color2, 0); FastLED.show();
}
}
"magicMatrix[x][y]!🧡"
Arduino Code 3:
#include <FastLED.h>
#define NUM_LEDS 576
#define DATA_PIN 4
CRGB leds[NUM_LEDS];
const int trigPin = 19;
const int echoPin = 18;
long randNumber;
long randNumber2;
long randNumber3;
long randNumber4;
long randNumber5;
long randNumber6;
long randNumber7;
long randNumber8;
long randNumber9;
long randNumber10;
long randNumber11;
long randNumber12;
long randNumber13;
long randNumber14;
long randNumber15;
long randNumber16;
long randNumber17;
long randNumber18;
long randNumber19;
long randNumber20;
long randNumber21;
long randNumber22;
long randNumber23;
long randNumber24;
long duration;
int distance;
int color = 255;
int color2 = 0;
int sound = 0;
void setup() {
randomSeed(color2);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(trigPin2, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin2, INPUT); // Sets the echoPin as an Input
pinMode(trigPin3, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin3, INPUT); // Sets the echoPin as an Input
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
Serial.begin(115200); // Starts the serial communication
}
void loop() {
color = map(distance, 18, 3, 255, 0);
color2 = map(distance, 18, 3, 0, 255);
sound = map(distance, 16, 1, 500, 2000);
randNumber = random(color);
randNumber2 = random(color);
randNumber3 = random(color);
randNumber4 = random(color);
randNumber5 = random(color);
randNumber6 = random(color);
randNumber7= random(color);
randNumber8 = random(color);
randNumber9 = random(color);
randNumber10 = random(color);
randNumber11 = random(color);
randNumber12 = random(color);
randNumber13 = random(color);
randNumber14 = random(color);
randNumber15 = random(color);
randNumber16 = random(color);
randNumber17 = random(color);
randNumber18 = random(color);
randNumber19 = random(color);
randNumber20 = random(color);
randNumber21 = random(color);
randNumber22 = random(color);
randNumber23 = random(color);
randNumber24 = random(color);
sensor();
toneMatrix();
ledsMatrix();
}
void toneMatrix() {
tone(16, sound, 10);
delay(10);
}
void ledsMatrix(){
for(int i=7; i < 15; i++)//1
{
leds[i].setRGB( color, color2, 0);
FastLED.show();
}
for(int i=71; i < 79; i++)//2
{
leds[i].setRGB( randNumber, randNumber2, randNumber3);
FastLED.show();
}
for(int i=135; i < 143; i++)//3
{
leds[i].setRGB( randNumber4, randNumber5, randNumber6);
FastLED.show();
}
for(int i=199; i < 207; i++)//4
{
leds[i].setRGB( randNumber7, randNumber8, randNumber9);
FastLED.show();
}
for(int i=263; i < 271; i++)//5
{
leds[i].setRGB( randNumber10, randNumber11, randNumber12);
FastLED.show();
}
for(int i=327; i < 335; i++)//6
{
leds[i].setRGB( randNumber13, randNumber14, randNumber15);
FastLED.show();
}
for(int i=391; i < 399; i++)//7
{
leds[i].setRGB( randNumber16, randNumber17, randNumber18);
FastLED.show();
}
for(int i=455; i < 503; i++)//8
{
leds[i].setRGB( randNumber19, randNumber20, randNumber21);
FastLED.show();
}
for(int i=519; i < 627; i++)//9
{
leds[i].setRGB( randNumber22, randNumber23, randNumber24);
FastLED.show();
}
}
void sensor() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
//Serial.print("Distance: ");
//Serial.println(distance);
}
"Sky Rails Matrix"
Arduino Code 4:
#define MOTOR_SPEED 100
//sensor pins
#define trigPin A1 //analog input 1
#define echoPin A2 //analog input 2
#define trigPin2 A3 //analog input 3
#define echoPin2 A4 //analog input 4
const int PIN_RED = 9;
const int PIN_GREEN = 12;
const int PIN_BLUE = 13;
const int buzzer = A0;
int RMotor_1 = 2;
int RMotor_2 = 3;
int LMotor_1 = 4;
int LMotor_2 = 5;
int REnable = 11;
int LEnable = 10;
int motor_speed;
long duration;
int distance;
long duration2;
int distance2;
bool direction = true;
void setup() {
Serial.begin(9600);
pinMode(buzzer, OUTPUT);
pinMode(PIN_RED, OUTPUT);
pinMode(PIN_GREEN, OUTPUT);
pinMode(PIN_BLUE, OUTPUT);
delay(1000);
pinMode(RMotor_1, OUTPUT);
pinMode(RMotor_2, OUTPUT);
pinMode(LMotor_1, OUTPUT);
pinMode(LMotor_2, OUTPUT);
pinMode(REnable, OUTPUT);
pinMode(LEnable, OUTPUT);
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
pinMode(trigPin2, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin2, INPUT); // Sets the echoPin as an Input
pinMode(buzzer, OUTPUT);
analogWrite(10, 100);
analogWrite(11, 100);
}
void loop() {
while (direction == true) {
sensor();
sensor2();
Serial.println("F");
Serial.print("Distance: ");
Serial.println(distance);
Serial.print("Distance 2 loop 1: ");
Serial.println(distance2);
move_forward();
randomTones_high();
analogWrite(PIN_RED, 0);
analogWrite(PIN_GREEN, 255);
analogWrite(PIN_BLUE, 0);
if (distance < 7){
direction = false;
}
}
while (direction == false) {
sensor();
sensor2();
Serial.println("B");
Serial.print("Distance: ");
Serial.println(distance);
Serial.print("Distance2 loop 2: ");
Serial.println(distance2);
move_backward();
randomTones_low();
analogWrite(PIN_RED, 255);
analogWrite(PIN_GREEN, 0);
analogWrite(PIN_BLUE, 0);
if (distance2 < 7){
direction = true;
}
}
}
void move_backward() {
digitalWrite(RMotor_1, HIGH);
digitalWrite(RMotor_2, LOW);
digitalWrite(LMotor_1, LOW);
digitalWrite(LMotor_2, HIGH);
}
void move_forward() {
digitalWrite(RMotor_1, LOW);
digitalWrite(RMotor_2, HIGH);
digitalWrite(LMotor_1, HIGH);
digitalWrite(LMotor_2, LOW);
}
void turn_right() {
digitalWrite(RMotor_1, HIGH);
digitalWrite(RMotor_2, LOW);
digitalWrite(LMotor_1, HIGH);
digitalWrite(LMotor_2, LOW);
}
void turn_left() {
digitalWrite(RMotor_1, LOW);
digitalWrite(RMotor_2, HIGH);
digitalWrite(LMotor_1, LOW);
digitalWrite(LMotor_2, HIGH);
}
void move_stop() {
digitalWrite(RMotor_1, LOW);
digitalWrite(RMotor_2, LOW);
digitalWrite(LMotor_1, LOW);
digitalWrite(LMotor_2, LOW);
}
void randomTones_high()
{
int randomBuzzer = random (800, 1000);
4 int randomBuzzerTime = random (1, 1000);
tone(buzzer, randomBuzzer, randomBuzzerTime);
delay(100); // delay in between reads for stability
}
void randomTones_low()
{
int randomBuzzer = random (20, 200);
int randomBuzzerTime = random (1, 800);
tone(buzzer, randomBuzzer, randomBuzzerTime);
delay(100); // delay in between reads for stability
}
void sensor() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
// Prints the distance on the Serial Monitor
// Serial.print("Distance: ");
// Serial.println(distance);
}
void sensor2() {
// Clears the trigPin
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration2 = pulseIn(echoPin2, HIGH);
// Calculating the distance
distance2 = duration2 * 0.034 / 2;
// Prints the distance on the Serial Monitor
// Serial.print("Distance: ");
// Serial.println(distance);
}