Hi,
I have a question about converting a serial reading into a value (e.g. 250).
I've bought the Adafruit 16-channel PWM and want to controll the brightness of a GRB-led (for learning how the board and library are working).
So I thought it would be nice to controll it via the commandline of the serial display of the arduino IDE.
Unfortunately it doesn't work with the code I'm using (a modified version of the adafruit examplesketch). My idea was that I have to converte the serial reading, but don't know how to do that.
I would be happy if someone had an idea what to do.
Below the code I'm running on my arduino.
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();// called this way, it uses the default address 0x40
int value_1=0;//value_1 has the value 0
void setup() {
Serial.begin(9600);
pwm.begin();//initialise the board
pwm.setPWMFreq(1000); // set the pulse frequency
uint8_t twbrbackup = TWBR; // save I2C bitrate
TWBR = 12; // upgrade to 400KHz (I2C communication speed)!
}
void loop() {
if (Serial.available()) // when characters arrive over the serial port...
{
delay(100); // wait a bit for the entire message to arrive
while (Serial.available() > 0) // read the available value
{
value_1=Serial.read();//value_1 stores the value from 'Serial.read'
}
}
pwm.setPWM(0,0,value_1);//blue (scematic: pwm.setPWM(output,minimum PWM value, max.PWM value))
pwm.setPWM(1,0,value_1);//green
pwm.setPWM(2,0,value_1);//blue
pwm.setPWM(3,0,value_1);//red
}
Thanks for help;)