Skip to content

Instantly share code, notes, and snippets.

@solennetadros
Created May 12, 2016 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save solennetadros/2f3b217bc3a5e424c4e053ff770dd92a to your computer and use it in GitHub Desktop.
Save solennetadros/2f3b217bc3a5e424c4e053ff770dd92a to your computer and use it in GitHub Desktop.
#include <CapacitiveSensor.h>
int moisturePin = A0;
int moistureValue;
//int touched;
#include <FastLED.h>
#define NUM_LEDS 60
#define DATA_PIN 13
CRGB leds[NUM_LEDS];
CapacitiveSensor cs_4_2 = CapacitiveSensor(4, 2); // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
void setup() {
Serial.begin(9600);
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
LEDS.setBrightness(10);
cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example
}
void loop() {
moisture();
touch ();
}
int moisture () {
moistureValue = analogRead(moisturePin);
int ledLen = map ( moistureValue, 36x0 , 900, NUM_LEDS, 0);
CRGB startColor, endColor;
startColor = CRGB :: Violet;
endColor = CRGB :: Green;
fill_gradient_RGB (leds, 0, startColor, ledLen - 1, endColor);
for (int i = ledLen; i < NUM_LEDS; i ++) {
leds[i].nscale8(10);
FastLED.show();
}
//Serial.print("sensor = ");
Serial.println(moistureValue);
}
int touch() {
long start = millis();
long total1 = cs_4_2.capacitiveSensor(30);
// Serial.print(millis() - start); // check on performance in milliseconds
Serial.println(total1);
Serial.print("\t");
// print sensor output 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment