12/12/2015
Led dimmer by using Potentiometer
Here's my codes,
const int LedPin = 3;
const int PotPin = 0;
static int val=0;
void setup() {
pinMode(LedPin, OUTPUT);
}
void loop() {
val = analogRead(PotPin);
LedTune();
analogWrite(LedPin, val);
}
void LedTune(){
val = map(val, 0, 1023, 0, 255);
val = constrain(val, 0, 255);
}
11/29/2015
Photoresistor, Arduino circuit.
Changing the light intensity of an LED by using a photo resistor.
And here's my codes,
const int PhotoPinNo = 0;
const int LedPinNo = 3;
int val;
void setup() {
pinMode(LedPinNo, OUTPUT);
}
void loop()
{
val = analogRead(PhotoPinNo);
BrightTune();
analogWrite(LedPinNo, val);
}
void BrightTune()
{
val = map(val, 450, 850, 255, 0);
val = constrain(val, 0, 255);
피드 구독하기:
글 (Atom)