i al ready learned about discreat components a long time ago. i also learned how to program things a long time ago. it has just been about 10 years since i have done any programing. so i will say this again, i want the pwm to follow what i have coming in on the input section of the controller
the controller
There's a definite article in that phrase, but we don't know from what you've told us thus far what 'the controller' might be.
You say you want the PWM to 'follow' the input, but haven't explained what that means.
Perhaps this extraction from a Arduino IDE example program called Calibration will show you an example of reading a changing analog input value and using that value to change the analogWrite() pwm fixed frequency, variable duty cycle output value.
void loop() {
// read the sensor:
sensorValue = analogRead(sensorPin);
// apply the calibration to the sensor reading
sensorValue = map(sensorValue, sensorMin, sensorMax, 0, 255);
// in case the sensor value is outside the range seen during calibration
sensorValue = constrain(sensorValue, 0, 255);
// fade the LED using the calibrated value:
analogWrite(ledPin, sensorValue);
}
Lefty
okay. the controller is the arduino. i already can read varying inputs on the serial port of the computer. the program is not selecting the proper frequancy due to conditions presented to it
PWM frequency is fixed, around 490Hz, IIRC.
after 12 beers and some target practice. thanks for your patienance everyone. i think i finally got this to work with just 2 inputs. now i need to write instances for 3 more. here is what im reading on the serial port:
pwm reads170
A0 reads
0
A1 reads
1022
pwm reads170
A0 reads
0
A1 reads
1022
pwm reads170
A0 reads
1023
A1 reads
1022
pwm reads170
A0 reads
1023
A1 reads
1022
pwm reads255
A0 reads
1023
A1 reads
0
pwm reads255
A0 reads
1023
A1 reads
0
pwm reads145
A0 reads
0
A1 reads
0
pwm reads145
A0 reads
0
A1 reads
0
pwm reads145
A0 reads
0
A1 reads
0
pwm reads145
A0 reads
0
A1 reads
0
pwm reads255
A0 reads
1023
A1 reads
0
pwm reads255
A0 reads
1023
A1 reads
1022
pwm reads255
A0 reads
1023
A1 reads
1022
pwm reads170
A0 reads
0
A1 reads
1022
and i did not have to change that much of my sample program here that is:
int keyVal1 = 0;
int keyVal2 = 0;
int keyVal3 = 0;
int keyVal4 = 0;
int keyVal5 = 0;
int PWM = 0;
void setup(){
Serial.begin(300); // diagnostic tool
pinMode(13, OUTPUT); // led output
pinMode(12, OUTPUT); // 12-4 key in
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
}
void loop(){
digitalWrite(12, HIGH); // turn on the keys (matrix input)
digitalWrite(11, HIGH);
digitalWrite(10, HIGH);
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
digitalWrite(7, HIGH);
digitalWrite(6, HIGH);
digitalWrite(5, HIGH);
digitalWrite(4, HIGH);
keyVal1=analogRead(A0); // read the matrix output
keyVal2=analogRead(A1);
keyVal3=analogRead(A2);
keyVal4=analogRead(A3);
keyVal5=analogRead(A4);
if(keyVal1>500 && keyVal2<500 && keyVal3<500 && keyVal4<500 && keyVal5<500)
{
PWM=255;
}
if(keyVal1>500 && keyVal2>500 && keyVal3<500 && keyVal4<500 && keyVal5<500)
{
PWM=255/1.01;
}
if(keyVal1>500 && keyVal2>500 && keyVal3>500 && keyVal4<500 && keyVal5<500)
{
PWM=255/1.02;
}
if(keyVal1>500 && keyVal2>500 && keyVal3>500 && keyVal4>500 && keyVal5<500)
{
PWM=255/1.03;
}
if(keyVal1>500 && keyVal2>500 && keyVal3>500 && keyVal4>500 && keyVal5>500)
{
PWM=255/1.04;
}
if(keyVal1>500 && keyVal2<500 && keyVal3>500 && keyVal4<500 && keyVal5<500)
{
PWM=255/1.05;
}
if(keyVal1>500 && keyVal2<500 && keyVal3>500 && keyVal4>500 && keyVal5<500)
{
PWM=255/1.06;
}
if(keyVal1>500 && keyVal2<500 && keyVal3>500 && keyVal4>500 && keyVal5>500)
{
PWM=255/1.07;
}
if(keyVal1>500 && keyVal2<500 && keyVal3<500 && keyVal4>500 && keyVal5<500)
{
PWM=255/1.08;
}
if(keyVal1>500 && keyVal2<500 && keyVal3<500 && keyVal4>500 && keyVal5>500)
{
PWM=255/1.09;
}
if(keyVal1>500 && keyVal2<500 && keyVal3<500 && keyVal4<500 && keyVal5>500)
{
PWM=255/1.1;
}
if(keyVal1<500 && keyVal2>500 && keyVal3<500 && keyVal4<500 && keyVal5<500)
{
PWM=255/1.11;
}
if(keyVal1<500 && keyVal2>500 && keyVal3>500 && keyVal4<500 && keyVal5<500)
{
PWM=255/1.12;
}
if(keyVal1<500 && keyVal2>500 && keyVal3>500 && keyVal4>500 && keyVal5<500)
{
PWM=255/1.13;
}
if(keyVal1<500 && keyVal2>500 && keyVal3>500 && keyVal4>500 && keyVal5>500)
{
PWM=255/1.14;
}
if(keyVal1<500 && keyVal2>500 && keyVal3<500 && keyVal4>500 && keyVal5<500)
{
PWM=255/1.15;
}
if(keyVal1<500 && keyVal2>500 && keyVal3<500 && keyVal4>500 && keyVal5>500)
{
PWM=255/1.16;
}
if(keyVal1<500 && keyVal2>500 && keyVal3<500 && keyVal4<500 && keyVal5>500)
{
PWM=255/1.17;
}
if(keyVal1<500 && keyVal2<500 && keyVal3>500 && keyVal4<500 && keyVal5<500)
{
PWM=255/1.18;
}
if(keyVal1<500 && keyVal2<500 && keyVal3>500 && keyVal4>500 && keyVal5<500)
{
PWM=255/1.19;
}
if(keyVal1<500 && keyVal2<500 && keyVal3>500 && keyVal4>500 && keyVal5>500)
{
PWM=255/1.2;
}
if(keyVal1<500 && keyVal2<500 && keyVal3>500 && keyVal4<500 && keyVal5>500)
{
PWM=255/1.21;
}
if(keyVal1<500 && keyVal2<500 && keyVal3<500 && keyVal4>500 && keyVal5<500)
{
PWM=255/1.22;
}
if(keyVal1<500 && keyVal2<500 && keyVal3<500 && keyVal4>500 && keyVal5>500)
{
PWM=255/1.23;
}
if(keyVal1<500 && keyVal2<500 && keyVal3<500 && keyVal4<500 && keyVal5>500)
{
PWM=255/1.24;
}
digitalWrite(13, HIGH);
delay(PWM*10);
digitalWrite(13, LOW);
delay(PWM*10);
Serial.print("pwm reads"); // diagnostic tool
Serial.println(PWM);
Serial.println("A0 reads");
Serial.println(keyVal1);
Serial.println("A1 reads");
Serial.println(keyVal2);
Serial.println("A2 reads");
Serial.println(keyVal3);
Serial.println("A3 reads");
Serial.println(keyVal4);
Serial.println("A4 reads");
Serial.println(keyVal5);
delay(5000);
}
the serial redings have started to match the combinations of inputs i am using. thank you all. i'm sure i will have another question about something else later