Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 92 characters in body
Source Link
jose can u c
  • 7k
  • 2
  • 17
  • 27

I have a basic set up of having a force sensitive resistor being used to power an LED as can be seen below. I am wondering how I can code it so that the LED is lit after a pressure has been applied to the FSR for a specified amount of time. Leading on from that I would like to use an RBG LED and have it so that after specified intervals on continuous pressure the LED changes colour. Any advice would be greatly appreciated.

//Constants:
const int ledPin = 3;     //pin 3 has PWM funtion
const int sensorPin = A0; //pin A0 to read analog input

//Variables:
int value; //save analog value


void setup(){
    
  pinMode(ledPin, OUTPUT);  //Set pin 3 as 'output' 
  Serial.begin(9600);       //Begin serial communication

}

void loop(){
  
  value = analogRead(sensorPin);       //Read and save analog value from potentiometer
  Serial.println(value);               //Print value
  value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
  analogWrite(ledPin, value);          //Send PWM value to led
  delay(100);                          //Small delay
  
}

const int ledPin = 3; //pin 3 has PWM funtion const int sensorPin = A0; //pin A0 to read analog input

//Variables: int value; //save analog value

void setup(){

pinMode(ledPin, OUTPUT); //Set pin 3 as 'output' Serial.begin(9600); //Begin serial communication

}

void loop(){

value = analogRead(sensorPin); //Read and save analog value from potentiometer Serial.println(value); //Print value value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM) analogWrite(ledPin, value); //Send PWM value to led delay(100); //Small delay

}

I have a basic set up of having a force sensitive resistor being used to power an LED as can be seen below. I am wondering how I can code it so that the LED is lit after a pressure has been applied to the FSR for a specified amount of time. Leading on from that I would like to use an RBG LED and have it so that after specified intervals on continuous pressure the LED changes colour. Any advice would be greatly appreciated.

//Constants:

const int ledPin = 3; //pin 3 has PWM funtion const int sensorPin = A0; //pin A0 to read analog input

//Variables: int value; //save analog value

void setup(){

pinMode(ledPin, OUTPUT); //Set pin 3 as 'output' Serial.begin(9600); //Begin serial communication

}

void loop(){

value = analogRead(sensorPin); //Read and save analog value from potentiometer Serial.println(value); //Print value value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM) analogWrite(ledPin, value); //Send PWM value to led delay(100); //Small delay

}

I have a basic set up of having a force sensitive resistor being used to power an LED as can be seen below. I am wondering how I can code it so that the LED is lit after a pressure has been applied to the FSR for a specified amount of time. Leading on from that I would like to use an RBG LED and have it so that after specified intervals on continuous pressure the LED changes colour. Any advice would be greatly appreciated.

//Constants:
const int ledPin = 3;     //pin 3 has PWM funtion
const int sensorPin = A0; //pin A0 to read analog input

//Variables:
int value; //save analog value


void setup(){
    
  pinMode(ledPin, OUTPUT);  //Set pin 3 as 'output' 
  Serial.begin(9600);       //Begin serial communication

}

void loop(){
  
  value = analogRead(sensorPin);       //Read and save analog value from potentiometer
  Serial.println(value);               //Print value
  value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
  analogWrite(ledPin, value);          //Send PWM value to led
  delay(100);                          //Small delay
  
}
Source Link

Coding force sensitive resistor to give output based on time used?

I have a basic set up of having a force sensitive resistor being used to power an LED as can be seen below. I am wondering how I can code it so that the LED is lit after a pressure has been applied to the FSR for a specified amount of time. Leading on from that I would like to use an RBG LED and have it so that after specified intervals on continuous pressure the LED changes colour. Any advice would be greatly appreciated.

//Constants:

const int ledPin = 3; //pin 3 has PWM funtion const int sensorPin = A0; //pin A0 to read analog input

//Variables: int value; //save analog value

void setup(){

pinMode(ledPin, OUTPUT); //Set pin 3 as 'output' Serial.begin(9600); //Begin serial communication

}

void loop(){

value = analogRead(sensorPin); //Read and save analog value from potentiometer Serial.println(value); //Print value value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM) analogWrite(ledPin, value); //Send PWM value to led delay(100); //Small delay

}