I am new to Arduino and currently been assigned to do light installation. The led strip should change it colour when the applied pressure varies. Below is the code I have done, please do have a look and give me some advice on whether it will work or not (I have not yet try on the circuit due to some limitations) ?
Moderators note : used code tags
C:
#include <Adafruit_NeoPixel.h>
#define LED_COUNT 30
#define LED_PIN 6
int sensorPin = A2;
int sensorValue = 0;
int ledValue;
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
pinMode (sensorPin, INPUT);
pinMode (LED_PIN, OUTPUT);
Serial.begin(9600);
strip.begin();
strip.show();
}
void loop() {
sensorValue = analogRead(sensorPin);
int ledValue = map(analogRead(sensorPin), 0, 1023, 0, 255);
Serial.print("sensorPin: ");
Serial.println(sensorValue);
Serial.print("\t ledValue: ");
Serial.println(ledValue);
if (ledValue<60){
strip.fill((255, 255, 255));
strip.show();
}
if (ledValue>=60 && ledValue<=80){
strip.fill((255, 0, 0));
strip.show();
}
else{
strip.fill((0, 0, 255));
strip.show();
}
delay(1000);
}