Devices & Components
Arduino Nano
Resistor 1M ohm
RGB Diffused Common Cathode
Hardware & Tools
Soldering iron (generic)
Project description
Code
RGB Led capacative touch interface
arduino
This program is written for an Acrylic engraved LED sign stand. The LED’s can be switch ON/OFF and the colour can be changed by touching the metal stand.
1// this programm is written by MBcreates (www.YouTube.com/MBcreates) 2// this program is in the public domain and free to use in any way you see fit 3 4//Credits: Paul Barger(https://playground.arduino.cc/Main/CapacitiveSensor?from=Main.CapSense) 5// https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use 6 7// LED used: ws1012-rgb-8mm-led 8// Resistor: 1 1m ohm 9 10 11 12#include <Adafruit_NeoPixel.h> 13#include <CapacitiveSensor.h> 14#define PIN 10 15#define LEDS 1 16 17int DELAY_TIME = 500; 18int COUNTER = 0; 19boolean LIGHT_STATE = false; 20 21Adafruit_NeoPixel strip = Adafruit_NeoPixel(LEDS, PIN ,NEO_GRB + NEO_KHZ800); 22CapacitiveSensor cs_4_2 = CapacitiveSensor(4,2); // 1 megohm resistor between pins 4 & 2, pin 2 is sensor pin, attach to metal body 23 24void setup() { 25 26 Serial.begin(9600); 27 28 cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF); // turn off autocalibrate on channel 1 - just as an example 29 Serial.begin(9600); 30 31 strip.begin(); 32 strip.show(); // 33 strip.setPixelColor(0, 69, 255, 0); // ORANGE RED 34 strip.show(); 35 36} 37 38void loop() { 39 40 long total1 = cs_4_2.capacitiveSensor(30); 41 42 if(total1>400) 43 { 44 COUNTER++ ; 45 } 46 47 else 48 { 49 COUNTER = 0; 50 } 51 52if((total1>400) && (!LIGHT_STATE)) 53{ 54 strip.setPixelColor(0, 69, 255, 0); // ORANGE RED 55 strip.show(); 56 delay(400); 57 LIGHT_STATE = true; 58} 59 60total1 = cs_4_2.capacitiveSensor(30); 61 62if((total1>400) && (LIGHT_STATE)) 63{ 64 65 strip.setPixelColor(0, 0, 0, 0); // ORANGE RED 66 strip.show(); //. 67 delay(400); 68 LIGHT_STATE = false; 69} 70 71while(COUNTER>3) // while loop to sellect the led colour 72{ 73 74 strip.setPixelColor(0, 255, 0, 0); //GREEN 75 strip.show(); //. 76 delay(DELAY_TIME); 77 78total1 = cs_4_2.capacitiveSensor(30); 79 80if(total1<400) 81{ 82 break; 83} 84 85 strip.setPixelColor(0,0, 255, 0); //RED 86 strip.show(); //. 87 delay(DELAY_TIME); 88 89total1 = cs_4_2.capacitiveSensor(30); 90 91if(total1<400) 92{ 93 break; 94} 95 96 strip.setPixelColor(0, 0, 0, 255); //BLUE 97 strip.show(); //. 98 delay(DELAY_TIME); 99 100total1 = cs_4_2.capacitiveSensor(30); 101 102if(total1<400) 103{ 104 break; 105} 106 107 strip.setPixelColor(0, 69, 255, 0); // ORANGE RED 108 strip.show(); //. 109 delay(DELAY_TIME); 110 111total1 = cs_4_2.capacitiveSensor(30); 112 113if(total1<400) 114{ 115 break; 116} 117 118 strip.setPixelColor(0, 255, 255, 10); // YELLOW 119 strip.show(); //. 120 delay(DELAY_TIME); 121 122total1 = cs_4_2.capacitiveSensor(30); 123 124if(total1<400) 125{ 126 break; 127} 128 129 130strip.setPixelColor(0, 69, 139, 19); // BROWN 131 strip.show(); //. 132 delay(DELAY_TIME); 133 134total1 = cs_4_2.capacitiveSensor(30); 135 136if(total1<400) 137{ 138 break; 139} 140 141 strip.setPixelColor(0, 0, 139, 139); // Purple 142 strip.show(); //. grb 143 delay(DELAY_TIME); 144 145 146total1 = cs_4_2.capacitiveSensor(30); 147 148if(total1<400) 149{ 150 break; 151} 152 153 154 155 strip.setPixelColor(0, 165, 218, 32); // GOLD 156 strip.show(); //. grb 157 delay(DELAY_TIME); 158 159total1 = cs_4_2.capacitiveSensor(30); 160 161if(total1<400) 162{ 163 break; 164} 165 166 167} 168 169} 170 171 172 173 174 175 176 177 178 179 180 181 182
Comments
Only logged in users can leave comments