Arduino LED+Force Sensor

Press to turn on the light
int sensorPin = A0;
int sensorValue;

//sensor value range: 0-1023
//200 is light touch
//500 is medium touch
//800 is hard touch
int limit = 200;


#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 20

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
 Serial.begin(9600);
 pinMode(13, OUTPUT);


    #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
  #endif
  // END of Trinket-specific code.

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}

void loop() {

 sensorValue = analogRead(sensorPin);
 Serial.print("Force Level: ");
 Serial.println(sensorValue);

 if (sensorValue > limit) {
 digitalWrite(13, HIGH);
 for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
 strip.setPixelColor(i, 125,0,125);         //  Set pixel's color (in RAM)
  strip.show();
 }
 }
 else {
 digitalWrite(13, LOW);
 strip.clear();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();
 }

 delay(100);
}
Press and light off
int sensorPin = A0;
int sensorValue;

//sensor value range: 0-1023
//200 is light touch
//500 is medium touch
//800 is hard touch
int limit = 200;


#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN    6

// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 20

// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
 Serial.begin(9600);
 pinMode(13, OUTPUT);


    #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
  #endif
  // END of Trinket-specific code.

  strip.begin();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();            // Turn OFF all pixels ASAP
  strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255)
}

void loop() {

 sensorValue = analogRead(sensorPin);
 Serial.print("Force Level: ");
 Serial.println(sensorValue);

 if (sensorValue > limit) {
 digitalWrite(13, HIGH);
 strip.clear();           // INITIALIZE NeoPixel strip object (REQUIRED)
  strip.show();

 }
else {
 digitalWrite(13, LOW);
  for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
  strip.setPixelColor(i, 125,0,125);         //  Set pixel's color (in RAM)
  strip.show();

 }

 delay(100);
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *