Isha Hans - Skills Dev II
Made by ihans
Made by ihans
Learning about inputs, sensors and conditional logic for creating Outputs
Created: November 10th, 2021
int flexPin = A0;
int flexReading = 0;
int ledPin = D2;
int ledBrightness = 0;
void setup() {
pinMode(ledPin, OUTPUT);
Particle.variable("snoopy", flexReading );
}
void loop() {
flexReading = analogRead(flexPin);
ledBrightness = map(flexReading, 0, 4095, 0, 255);
analogWrite(ledPin, ledBrightness);
delay(100);
}
int ledPin = D2;
int buttonPin = D3;
int buttonState;
int potPin = A5;
int potReading = 0;
void setup() {
pinMode( buttonPin, INPUT_PULLUP);
pinMode( ledPin, OUTPUT);
}
void loop() {
potReading = analogRead( potPin );
int brightness = map( potReading, 0, 4095, 0, 255 );
analogWrite( ledPin, brightness );
// int buttonReading = digitalRead( buttonPin);
// int buttonState = digitalRead( buttonPin );
// if( buttonState == LOW) {
// digitalWrite( ledPin, HIGH);
// }else{
// digitalWrite( ledPin, LOW);
// }
delay( 500 );
}
Click to Expand
Exercise 2: Using Flex Sensor to indicate availability
Use Scenario
When I'm working on my desk in the studio, I often get disturbed by peers wanting to chat or ask a question. This sometimes breaks my flow of work and I would really appreciate a subtle way of communicating when is it okay for someone to disturb me and when it's an absolute DND. Therefore, I hope to design a phone holder that gives out warnings when I pick up the phone.
Input:
- Switch: turn the light system on/off
- Flex Sensor (FSR): sense the bend
Output:
- Switch: turn the light system on/off
- (when the flex sensor is bent halfway): low brightness of LED
- (when the flex sensor is all the way): high brightness of LED
int flexPin = A0;
int flexReading = 0;
int ledPin = D2;
int ledBrightness = 0;
int switchPin = D3;
void setup() {
pinMode( switchPin , INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
Particle.variable("floopy", flexReading );
Particle.variable("brightness", ledBrightness );
}
void loop() {
int buttonState = digitalRead( switchPin );
if( buttonState == LOW ) {
digitalWrite( ledPin, HIGH);
flexReading = analogRead(flexPin);
ledBrightness = map(flexReading, 100, 1500, 0, 255);
analogWrite(ledPin, ledBrightness);
delay(500);
}else{
digitalWrite( ledPin, LOW);
}
}
Click to Expand