You said "wrapper".... and they're, in my head, people who make music that makes my head hurt.
if (analogRead(sw1) > 1015 && analogRead(sw1) < 1024 )
{
buttonPushed1 = 1;
}
if (buttonPushed1) {
angle1 = angle1 + angleStep1;
if (angle1 <= 0 || angle1 >= 180) {
angleStep1 = -angleStep1;
buttonPushed1 = 0;
if (angle1 <= 0) {
lcd.setCursor(0, 0);
lcd.print("Point 01 is set ");
leda[0].setRGB(16, 16, 8);
ledb[0].setRGB(0, 0, 0);
digitalToggle(ex1, 0);
}
else if (angle1 >= 180) {
lcd.setCursor(0, 0);
lcd.print("Point 01 is thrown ");
leda[0].setRGB(0, 0, 0);
ledb[0].setRGB(16, 16, 8);
digitalToggle(ex1, 0);
}
}
pwm0.setPWM(0, 0, angleToPulse(angle1) );
}
That is my current code which receives the information from the switch and then does the 'deed'. In the fact that it changes a PWM servo, changed an LED on or off, and changes a relay. I know there are far easier ways to code this, but I understand it!! And I'd really like to be able to understand all that I code.
I have 36 switches and while I have enough space on my Mega, I'd rather use an i2c or other method if I can as it uses less wiring. I have gone to three inputs into a analogue input on the Mega, as I can get about ten switches on each, which have a resistor between each switch to give different levels, then read that into the mega to know which switch has been triggered. While it works really well and only uses 3 unused Analogue inputs, I have also found it a tad temperamental on occasion. About 1 in 20 switch throws, might throw another switch on the row. While I could ignore it, I'd rather do it properly.
So, this is why I've brought out the multiple i2c route.
I already have 5 PCF8574s in use and they control the relays. I need 6 more in order to have all switches controlled by the PCF8574s. You can't do that though due to running out of 0x's.
So, I am using the TCA9548 in order to extend that.
What I'd like to be able to do is go back to what I had before which was below:
if (digitalRead(pushButton1) == LOW)
{
buttonPushed1 = 1;
}
if (buttonPushed1) {
angle1 = angle1 + angleStep1;
if (angle1 <= 0 || angle1 >= 180) {
angleStep1 = -angleStep1;
buttonPushed1 = 0;
if (angle1 <= 0) {
lcd.setCursor(0, 0);
lcd.print("Point 01 is set ");
leda[0].setRGB(32, 16, 0);
ledb[0].setRGB(0, 0, 0);
}
else if (angle1 >= 180) {
lcd.setCursor(0, 0);
lcd.print("Point 01 is thrown ");
leda[0].setRGB(0, 0, 0);
ledb[0].setRGB(32, 16, 0);
}
}
pwm0.setPWM(0, 0, angleToPulse(angle1) );
}
Which simply read a previously defined pushButton1 :
#define pushButton1 2
Except rather than having it #define pushButton1 as pin 2, have it say #define pushButton1 as 0x71(2) or whatever the code would be.
Does that make sense?