Mapping
This project demonstrates an RGB LED controlled through a switch-based input system, where user interaction directly affects the color output of the light. The strength of which is determined by how far the user slides the potentiometer on the breadboard. The potentiometer functions as the primary and only way to provide user input. It sends signals that allows the light of the LED to appear blue when activated and increase it's brightness overall. The RGB LED switch emphasizes the relationship between hardware inputs, some minor software logic and visual output. Internally, the microcontroller reads the switch’s state and maps it to strength of the blue color in the LED. demonstrating basic input mapping and conditional logic. Displaying how user interaction can dynamically shape an electronic system’s behavior. This project serves as a practical example of physical computing design at a small scale.
Sketch
Schematic
Pictures
Video Demonstration
Code
const int bluePin = 9;
const int greenPin = 10;
const int redPin = 11;
const int thePin = A1;
int maxVal = 0;
int minVal = 1023;
void setup() {
// put your setup code here, to run once:
pinMode (bluePin, OUTPUT);
pinMode (greenPin, OUTPUT);
pinMode (redPin, OUTPUT);
pinMode (thePin, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println(analogRead(thePin));
int knobval = analogRead(thePin);
if (knobval > maxVal) maxVal = knobval;
if (knobval < minVal) minVal = knobval;
int mapval = map(knobval, minVal, maxVal, 0, 255);
analogWrite(redPin, mapval);
delay(10);
Serial.print(knobval);
Serial.print("\t");
Serial.print(minVal);
Serial.print("\t");
Serial.println(maxVal);
//for(int i=0; i<255 analogwrite="" bluepin="" code="" delay="" greenpin="" i="" redpin="">255>



No comments:
Post a Comment
Note: Only a member of this blog may post a comment.