Hi all,
I am a beginner with programming and unfortunately I need help with next issue:
1st - explanation of purpose - designed HW is on base Arduino uno and myself made "power shield" - board with resistors and 3 pcs. MOSFET transistos for driving of 50W power LED clusters - it meaning independent dimming (PWM outs) of each one from these 3 clusters (charged by 12V cross MOSFET transistor). Arduino program idea - By two inputs - for example In 2, 3 (in fact will be represented by buttons) it will driven one PWM out - for example Out 9. By pressing button 2 it will cause increasing brightness (by change of character PWM) on Out 9, By pressing button 3 it will cause decreasing brightness (by change of character PWM) on out 9. Well - this now working for 2 inputs and one output and I need it for another two outs - In fact - summary - as I wrote - 3 independent circuits contains 2+2+2 inputs and 1+1+1 PWM out - of course - each circuit must be controlled independent.
2nd - program problem - As I wrote - for one circuit it program working well - Lets see:
int brightness = 10; // how bright the LED is
void setup() {
// declare pin 9 to be an output:
pinMode(9, OUTPUT);
// declare pin 2(up) & 3(down) to be an output:
pinMode(2, INPUT);
pinMode(3, INPUT);
TCCR1B = TCCR1B & 0b11111000 | 0x03; //change frequency on 9,10 value 0x05 lower to 0x1 higher
}
void loop() {
if(brightness<255)
brightness+=digitalRead(2); //increase brightness level by 1 if up is pressed else do nothing
if(brightness>0)
brightness-=digitalRead(3); //decrease brightness level by 1 if down is pressed else do nothing
// set the brightness of pin 9:
analogWrite(9, brightness);
delay(200); // wait for 200 milliseconds to see the dimming effect
So - because I am an "idealist" and I was suppose, than is enough to simply extend and rename list of in/outs and "loop" core and it will work - ehm... well - in fact - does not work as i like. In real it work little bit confused - Each from all 6 inputs control of all 3 outs. For example - by pressing button for controling input No2 (for increasing falue PWM on Output No 9) it automatically changed value also on other outs No 5,6.
I need somehow separate these three blocks in program to "independent blocks" that they will not take a affect to another one
In fact:
- by Inputs 2,3 I need control only Output 9
- by Inputs 7,8 I need control only Output 5
- by Inputs 12, 13 I need control only Output 6
here is my not working experiment - if you can anybody help me wit that... Many Thx.
int brightness = 5; // how bright the LED is
void setup() {
pinMode(9, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(12, INPUT);
pinMode(13, INPUT);
}
void loop() {
if(brightness<255)
brightness+=digitalRead(2); //increase brightness level by 1 if up is pressed else do nothing
if(brightness>0)
brightness-=digitalRead(3); //decrease brightness level by 1 if down is pressed else do nothing
analogWrite(9, brightness);
delay(100);
if(brightness<255)
brightness+=digitalRead(7); //increase brightness level by 1 if up is pressed else do nothing
if(brightness>0)
brightness-=digitalRead(8); //decrease brightness level by 1 if down is pressed else do nothing
delay(100);
analogWrite(5, brightness);
if(brightness<255)
brightness+=digitalRead(12); //increase brightness level by 1 if up is pressed else do nothing
if(brightness>0)
brightness-=digitalRead(13); //decrease brightness level by 1 if down is pressed else do nothing
analogWrite(6, brightness);
delay(100); // wait for 100 milliseconds to see the dimming effect
}