Hello Everyone!
I'm New in this forum. I need a bit of help with my project.
I want to dim a 220 ac dimmable led using either Bluetooth app(made with MIT App Inventor 2) and potentiometer.
I can dim the led using either method but, I need to re-upload the sketch of the either the Bluetooth or potentiometer.
Here the code I made so far:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to.
const int ledPin = 9; // Needs to be a pin supporting PWM.
int value = -1;
int analogValue = 0;
int sensorValue = -1; // value read from the pot
String inputString = "" ;
char junk;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop()
{
if (Serial.available())
{
while (Serial.available()) // Read while there is data in the buffer
{
char c = Serial.read(); //read the input
inputString += c; //make a string of the characters coming on serial
}
while (Serial.available())
{
junk = Serial.read(); // clear the serial buffer
}
if (inputString == "a")
{
value = Serial.read();
{
if (value >= 0) // If we have meaningful data
{
Serial.println(value); // Debug - double check it make sense
analogWrite(ledPin, value); // set PWM for LED brightness
value = -1;
}
}
}
else if (inputString != "a")
{
sensorValue = analogRead(analogInPin); // read the analog in value:
analogValue = map(sensorValue, 0, 1023, 0, 256); // map it to the range of the analog out:
analogWrite(ledPin, analogValue); // change the analog out value:
}
inputString = "";
}
}