/* ---------------------------------------------------------
* | Experimentation Kit for Arduino Example Code |
* | CIRC-14 .: Fancy Sensing :. (Soft Potentiometer) |
* ---------------------------------------------------------
*
* Will fade an RGB LED from Red-Green-Blue in relation to the
* soft pot value
*
*/
// LED leads connected to PWM pins
const int RED_LED_PIN = 9; //Red LED Pin
const int GREEN_LED_PIN = 10; //Green LED Pin
const int BLUE_LED_PIN = 11; //Blue LED Pin
void setup() {
//no need for any code here
}
void loop() {
int sensorValue = analogRead(0); //read the Soft Pot
int redValue = constrain(map(sensorValue, 0, 512, 255, 0),0,255); //calculate the red Value (255-0 over the range 0-512)
int greenValue = constrain(map(sensorValue, 0, 512, 0, 255),0,255)-constrain(map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the green value (0-255 over 0-512 & 255-0 over 512-1023)
int blueValue = constrain(map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the blue value 0-255 over 512-1023
// Display the requested color
analogWrite(RED_LED_PIN, redValue);
analogWrite(GREEN_LED_PIN, greenValue);
analogWrite(BLUE_LED_PIN, blueValue);
} "http://ardx.org/HSB
To convert from RGB to HSB all that is required is some slightly complicated math. Visit http://ardx.org/CODE14MB based on www.kasperkamperman.com's original code: http://ardx.org/KASP
Faux buttons:
Define a range of values corresponding to a discrete button.
if(analogRead(0) > minValue &&
analogRead(0) < maxValue) {
buttonAction()
}
Then cover the soft pot with a drawn/printed button pattern."
* | Experimentation Kit for Arduino Example Code |
* | CIRC-14 .: Fancy Sensing :. (Soft Potentiometer) |
* ---------------------------------------------------------
*
* Will fade an RGB LED from Red-Green-Blue in relation to the
* soft pot value
*
*/
// LED leads connected to PWM pins
const int RED_LED_PIN = 9; //Red LED Pin
const int GREEN_LED_PIN = 10; //Green LED Pin
const int BLUE_LED_PIN = 11; //Blue LED Pin
void setup() {
//no need for any code here
}
void loop() {
int sensorValue = analogRead(0); //read the Soft Pot
int redValue = constrain(map(sensorValue, 0, 512, 255, 0),0,255); //calculate the red Value (255-0 over the range 0-512)
int greenValue = constrain(map(sensorValue, 0, 512, 0, 255),0,255)-constrain(map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the green value (0-255 over 0-512 & 255-0 over 512-1023)
int blueValue = constrain(map(sensorValue, 512, 1023, 0, 255),0,255); //calculate the blue value 0-255 over 512-1023
// Display the requested color
analogWrite(RED_LED_PIN, redValue);
analogWrite(GREEN_LED_PIN, greenValue);
analogWrite(BLUE_LED_PIN, blueValue);
} "http://ardx.org/HSB
To convert from RGB to HSB all that is required is some slightly complicated math. Visit http://ardx.org/CODE14MB based on www.kasperkamperman.com's original code: http://ardx.org/KASP
Faux buttons:
Define a range of values corresponding to a discrete button.
if(analogRead(0) > minValue &&
analogRead(0) < maxValue) {
buttonAction()
}
Then cover the soft pot with a drawn/printed button pattern."
No comments:
Post a Comment