Hello I am creating a light up scarf that turns on during the night and through pressure through user input the light will flash .
Currently with the code I have, the light sensor isn't work in yet and the pressure sensor when pressed makes the LED go brighter, but I am confused how to code the but where to make the light sensor make the lights turn ON when it is dark and to get the pressure sensor to flash and then OFF completely when there is light
hope you can all help
Here is my code so far:
// constants won't change
const int ANALOG_THRESHOLD = 340;
// variables will change:
int analogValue;
int led_pin = 10;
int fsrAnalogPin = A3; // FSR is connected to analog 3)
int fsrReading; // the analog reading from the FSR resistor divider
int LEDbrightness;
int LIGHT_SENSOR_PIN = A2;
void setup() {
Serial.begin(9600); // We'll send debugging information via the Serial monitor
pinMode(led_pin, OUTPUT); // set arduino pin to output mode
pinMode(fsrAnalogPin, INPUT);
}
void loop(void) {
analogValue = analogRead(LIGHT_SENSOR_PIN); // read the input on analog pin
fsrReading = analogRead(fsrAnalogPin);
Serial.print("Analog reading = ");
Serial.println(LIGHT_SENSOR_PIN);
LEDbrightness = map(fsrReading, 0, 480, 0, 255);
if(fsrReading > ANALOG_THRESHOLD){
analogWrite(led_pin, HIGH);
delay(100);
analogWrite(led_pin, LOW);// This is to blink the LED
delay(100);
}
else{
// delay(1000);
analogWrite(led_pin, HIGH); // turn off LED
}
// LED gets brighter the harder you press
analogWrite(led_pin, LEDbrightness);
delay(10);
}
Dont do it all at once in one sketch. You need to work out exactly what you need and describe it better. The microcontroller can’t do interpretation and will only do exactly as you code.
Start a new sketch for each one of you sensors. Get it working as an input and save it. Start a sketch for lights and get them working.
Look up state machines and probably switch case would be best.
Think about how many states your project will have and code functions for each state. Use the variables returned by your sensors to trigger the appropriate state and its corresponding function
Look up blink without delay example and understanding non blocking code
All projects are just lots of simple things put together and the biggest mistake is to do it all as one thing. Complexity is the end result.
Hi,
Can you please post a circuit diagram?
So we can see how you have your LEDs configured, pressure switch and light sensor are wired.
Can you please post a link to data/specs of the pressure switch and light sensor?
Do you have code that JUST reads the pressure switch, to prove your code?
Do you have code the JUST fades your LEDs up and down, to prove your code?
Do you have code that JUST reads your light sensor, to prove your code?