|
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
153 Posts
|
With rotary encoder
To Skystream and others,
You we're right, the EEPROM is easier then I thought. I've connected a rotary encoder to pin A8 and A9. A temporary reset connected to A10. The encoder has 3 pin on a side. The middle pin is connented to GND. The other two have a 10K resistor to 5V and are connected to A8 and A9. The other side has two pins. One goes to A10 and has a 10k pulldown resistor to gnd. The other pin goes to 5V. Don't rotate the encoder to fast, it needs time to read. The value the arduino needs to remember goes to EEPROM address 0. The code still needs some cleaning up. You now have two ways to select a channel. 1: 10K pot and a seperate reset button, or 2: the rotary encoder. The rotary version can set a channel from 01 to 99
Time to build the demo transmitter version and also implement the rotary encoder next to the pot selection. My old transmitter needs reworking  .
grtz.
Danny
EDIT: code REALLY needs cleaning up.
Code:
#include <Servo.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <Wire.h>
#include <EEPROM.h>
#define expander1 B0111000
#define expander2 B0100000
const int chlow = 80; // set lowest channel number with pot channel selection
const int chhi = 99; // set highest channel number with pot channel selection
//#define DEBUG // uncomment for feedback through the serialmonitor
//#define DynChannel // comment for setting dynamic channel select.
// Ananolg pin 13 for potmeter. Reset to use channel
//#define RESET // do you have want resetbutton?
// Stick it on pin A15, and add a 10K pulldown. Led on pin A14
#define DynChannelrotary // channel select and push for selecting the channel
int channel = 80; // what channel are we on? // comment for dynamic channel control
int channelold;
char buffer[64];
char msg[140] = "";
int b;
// let's define some servo's
Servo servo1; Servo servo2; Servo servo3; Servo servo4;
Servo servo5; Servo servo6; /*Servo servo7; Servo servo8; */
Servo servo9; Servo servo10; Servo servo11; Servo servo12;
// minimum and maximum range for the servo
int servmin1 = 16; int servmax1 = 177;
int servmin2 = 16; int servmax2 = 177;
int servmin3 = 16; int servmax3 = 177;
int servmin4 = 16; int servmax4 = 177;
int servmin5 = 16; int servmax5 = 177;
int servmin6 = 16; int servmax6 = 177;
/*int servmin7 = 0; int servmax7 = 255;
int servmin8 = 0; int servmax8 = 255;*/
int servmin9 = 16; int servmax9 = 177;
int servmin10 = 16; int servmax10 = 177;
int servmin11 = 16; int servmax11 = 177;
int servmin12 = 16; int servmax12 = 177;
int pinNumber; int pinValue;
int Pin22 = 22; int Pin23 = 23; int Pin24 = 24; int Pin25 = 25;
int Pin26 = 26; int Pin27 = 27; int Pin28 = 28; int Pin29 = 29;
int Pin30 = 30; int Pin31 = 31; int Pin32 = 32; int Pin33 = 33;
int Pin34 = 34; int Pin35 = 35; int Pin36 = 36; int Pin37 = 37;
int Pin38 = 38; int Pin39 = 39; int Pin40 = 40; int Pin41 = 41;
int Pin42 = 42; int Pin43 = 43; int Pin44 = 44; int Pin45 = 45;
int Pin46 = 46; int Pin47 = 47; int Pin48 = 48; int Pin49 = 49;
int Pin53 = 53; int Pin8 = A0; int Pin9 = A1; int Pin10 = A2;
int Pin11 = A3; int Pin12 = A4; int Pin13 = A5;
int Pin14 = A6; int Pin15 = A7;
#ifdef RESET
const int resetPin = A15; // the number of the pushbutton pin
const int ResetState = 0; // variable for reading the pushbutton status
const int resetled = A14; // light up led when reset
const int timetoreset = 500; // how long delay after reset
#endif
#ifdef DynChannel // read with
const int ChannelPin = A13; // select the input pin for the channel select
int ChannelValue = 0; // temp. channel until read
//int channelold; // just needed as a default when setting channel dynamic
#endif
#ifdef DynChannelrotary
int address = 1;
const int ResetState = 0; // variable for reading the pushbutton status
const int timetoreset = 1000; // how long delay after reset
int ChannelValue = 0; // temp. channel until read
const int Pin_Highbit =A8; // first pin of rotary
const int Pin_Lowbit =A9; // third pin of rotary
const int buttonPin = A10; // the number of the pushbutton pin (temp A10 -> A15
int rotarychannel = 1;
int value;
int state, prevState = 0, count = 0;
int pushed = 0; int buttonState = 0;
int encoderStates[4][4] = {
{ 0, -1, 1, 0 },
{ 1, 0, 0, -1 },
{ -1, 0, 0, 1 },
{ 0, 1, -1, 0 },
};
#endif
// nRF24L01(+) radio attached to SPI and pins 8 & 9
RF24 radio(8,9);
// Network uses that radio
RF24Network network(radio);
// Address of our node
const uint16_t this_node = 0; // the receiver code
// Address of the other node
const uint16_t other_node = 1; // the transmittercode
void defaultvalues(){
}
void setup(void)
{
#ifdef RaspberryPiComm
Serial.begin(115200);
#endif
#ifdef DynChannelrotary
pinMode(Pin_Highbit, INPUT);
pinMode(Pin_Lowbit, INPUT);
digitalWrite(Pin_Lowbit, HIGH);
digitalWrite(Pin_Highbit, HIGH);
pinMode(buttonPin, INPUT);
#endif
Wire.begin();
pinMode(Pin22, OUTPUT); pinMode(Pin23, OUTPUT);
pinMode(Pin24, OUTPUT); pinMode(Pin25, OUTPUT);
pinMode(Pin26, OUTPUT); pinMode(Pin27, OUTPUT);
pinMode(Pin28, OUTPUT); pinMode(Pin29, OUTPUT);
pinMode(Pin30, OUTPUT); pinMode(Pin31, OUTPUT);
pinMode(Pin32, OUTPUT); pinMode(Pin33, OUTPUT);
pinMode(Pin34, OUTPUT); pinMode(Pin35, OUTPUT);
pinMode(Pin36, OUTPUT); pinMode(Pin37, OUTPUT);
pinMode(Pin38, OUTPUT); pinMode(Pin39, OUTPUT);
pinMode(Pin40, OUTPUT); pinMode(Pin41, OUTPUT);
pinMode(Pin42, OUTPUT); pinMode(Pin43, OUTPUT);
pinMode(Pin44, OUTPUT); pinMode(Pin45, OUTPUT);
pinMode(Pin46, OUTPUT); pinMode(Pin47, OUTPUT);
pinMode(Pin48, OUTPUT); pinMode(Pin49, OUTPUT);
pinMode(Pin53, OUTPUT);
pinMode(Pin8, OUTPUT); pinMode(Pin9, OUTPUT);
pinMode(Pin10, OUTPUT); pinMode(Pin11, OUTPUT);
pinMode(Pin12, OUTPUT); pinMode(Pin13, OUTPUT);
pinMode(Pin14, OUTPUT); pinMode(Pin15, OUTPUT);
digitalWrite(Pin22, LOW); digitalWrite(Pin23, LOW);
digitalWrite(Pin24, LOW); digitalWrite(Pin25, LOW);
digitalWrite(Pin26, LOW); digitalWrite(Pin27, LOW);
digitalWrite(Pin28, LOW); digitalWrite(Pin29, LOW);
digitalWrite(Pin30, LOW); digitalWrite(Pin31, LOW);
digitalWrite(Pin32, LOW); digitalWrite(Pin33, LOW);
digitalWrite(Pin34, LOW); digitalWrite(Pin35, LOW);
digitalWrite(Pin36, LOW); digitalWrite(Pin37, LOW);
digitalWrite(Pin38, LOW); digitalWrite(Pin39, LOW);
digitalWrite(Pin40, LOW); digitalWrite(Pin41, LOW);
digitalWrite(Pin42, LOW); digitalWrite(Pin43, LOW);
digitalWrite(Pin44, LOW); digitalWrite(Pin45, LOW);
digitalWrite(Pin46, LOW); digitalWrite(Pin47, LOW);
digitalWrite(Pin48, LOW); digitalWrite(Pin49, LOW);
digitalWrite(Pin53, LOW);
digitalWrite(Pin8, LOW); digitalWrite(Pin9, LOW);
digitalWrite(Pin10, LOW); digitalWrite(Pin11, LOW);
digitalWrite(Pin12, LOW); digitalWrite(Pin13, LOW);
digitalWrite(Pin14, LOW); digitalWrite(Pin15, LOW);
#ifdef RESET
pinMode(resetPin, INPUT);
pinMode(resetled, OUTPUT);
#endif
Serial.begin(9600);
#ifdef DEBUG
Serial.println("RF24Network/nummeriek protocol ontvangerzijde");
Serial.print("Encoder channel: ");
Serial.println(channel);
#endif
// sound serial 1
// Serial1.begin(9600);
// what servo goes in what port
servo1.attach(2); servo2.attach(3); servo3.attach(4); servo4.attach(5);
servo5.attach(6); servo6.attach(7); /*servo7.attach(10); servo8.attach(11); */
servo9.attach(10); servo10.attach(11); servo11.attach(12); servo12.attach(13);
#ifdef DynChannel
ChannelValue = analogRead (ChannelPin);
int channel = map(ChannelValue,0,1023,chlow,chhi);
b = channel;
if (b==0){expanderWrite1(B10111110);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11111110);b=b-80;}
if (b>=70){expanderWrite1(B00110010);b=b-70;}
if (b>=60){expanderWrite1(B11101110);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010010);b=b-40;}
if (b>=30){expanderWrite1(B01110110);b=b-30;}
if (b>=20){expanderWrite1(B10111100);b=b-20;}
if (b>=10){expanderWrite1(B00010010);b=b-10;}
//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B10111110);}
if (b==1){expanderWrite2(B00010010);}
if (b==2){expanderWrite2(B01111100);}
if (b==3){expanderWrite2(B01110110);}
if (b==4){expanderWrite2(B11010010);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11101110);}
if (b==7){expanderWrite2(B00110010);}
if (b==8){expanderWrite2(B11111110);}
if (b==9){expanderWrite2(B11110110);}
//Serial.println(channel);
delay(10);
#endif
#ifdef DynChannelrotary
value = EEPROM.read(0);
delay(100);
count = value*4;
//count = count*4;
channel = count/4;
//channel = channel / 4;
//Serial.println(value,DEC);
//delay(1000);
b = channel;
if (b==0){expanderWrite1(B10111110);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11111110);b=b-80;}
if (b>=70){expanderWrite1(B00110010);b=b-70;}
if (b>=60){expanderWrite1(B11101110);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010010);b=b-40;}
if (b>=30){expanderWrite1(B01110110);b=b-30;}
if (b>=20){expanderWrite1(B10111100);b=b-20;}
if (b>=10){expanderWrite1(B00010010);b=b-10;}
//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B10111110);}
if (b==1){expanderWrite2(B00010010);}
if (b==2){expanderWrite2(B01111100);}
if (b==3){expanderWrite2(B01110110);}
if (b==4){expanderWrite2(B11010010);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11101110);}
if (b==7){expanderWrite2(B00110010);}
if (b==8){expanderWrite2(B11111110);}
if (b==9){expanderWrite2(B11110110);}
//Serial.println(channel);
delay(10);
#endif
SPI.begin();
radio.begin();
network.begin(/*channel*/ channel, /*node address*/ this_node);
#ifdef commpin53
digitalWrite(commpin,HIGH);
#endif
}
#ifdef RESET
void(* resetFunc) (void) = 0; //declare reset function @ address 0
#endif
#ifdef DynChannelrotary
void(* resetFunc) (void) = 0; //declare reset function @ address 0
#endif
void loop(void)
{
#ifdef DynChannelrotary
state = (digitalRead(Pin_Highbit) << 1) | digitalRead(Pin_Lowbit);
count += encoderStates[prevState][state];
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed and debounce
if (buttonState == HIGH && pushed==0) {// reset pushed
// Reset:
Serial.print("eeprom value: "); Serial.println(value);
EEPROM.write(0, value);
delay(timetoreset);
resetFunc(); //call reset
pushed =1;
}
if (buttonState == LOW && pushed==1) {// reset released
// do nothing
pushed=0;
}
prevState = state;
if (state != prevState) {}// perhaps in the future
if (count <=0){count=0;} // nothing less then 0
channel = count/4;
if (count >=396){count=396;} // nothing more then 396
b = channel;
if (channel != channelold){
//if (b==0){expanderWrite1(B01110111);}
if (b<10){expanderWrite1(B01111110);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11111110);b=b-80;}
if (b>=70){expanderWrite1(B00110010);b=b-70;}
if (b>=60){expanderWrite1(B11101110);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010010);b=b-40;}
if (b>=30){expanderWrite1(B10110110);b=b-30;}
if (b>=20){expanderWrite1(B10111100);b=b-20;}
if (b>=10){expanderWrite1(B00010010);b=b-10;}
//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B10111110);}
if (b==1){expanderWrite2(B00010010);}
if (b==2){expanderWrite2(B01111100);}
if (b==3){expanderWrite2(B01110110);}
if (b==4){expanderWrite2(B11010010);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11101110);}
if (b==7){expanderWrite2(B00110010);}
if (b==8){expanderWrite2(B11111110);}
if (b==9){expanderWrite2(B11110110);}
delay(10);
value = count/4;
//Serial.print(value); Serial.print(" / "); Serial.println(channel);
}
#endif
#ifdef RESET
// reset button
int ResetState = analogRead(resetPin);
if (ResetState >= 10) {
// analogWrite(resetled,100); // just ot test button
delay(timetoreset);
resetFunc(); //call reset
}
else {
// analogWrite(resetled,20);
}
#endif
#ifdef DynChannel
ChannelValue = analogRead (ChannelPin);
int channel = map(ChannelValue,0,1023,chlow,chhi);
b = channel;
if (channel != channelold){
if (b==0){expanderWrite1(B01110111);}
if (b==0){expanderWrite1(B10111110);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11111110);b=b-80;}
if (b>=70){expanderWrite1(B00110010);b=b-70;}
if (b>=60){expanderWrite1(B11101110);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010010);b=b-40;}
if (b>=30){expanderWrite1(B01110110);b=b-30;}
if (b>=20){expanderWrite1(B10111100);b=b-20;}
if (b>=10){expanderWrite1(B00010010);b=b-10;}
//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B10111110);}
if (b==1){expanderWrite2(B00010010);}
if (b==2){expanderWrite2(B01111100);}
if (b==3){expanderWrite2(B01110110);}
if (b==4){expanderWrite2(B11010010);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11101110);}
if (b==7){expanderWrite2(B00110010);}
if (b==8){expanderWrite2(B11111110);}
if (b==9){expanderWrite2(B11110110);}
delay(10);
}
#endif
#ifdef DEBUG
if (channelold != channel){
Serial.print("Channel: ");
Serial.print(channel);
Serial.print(" ");
channelold = channel;
}
#endif
// Pump the network regularly
network.update();
// Is there anything ready for us?
while ( network.available() )
{
// If so, grab it and print it out
RF24NetworkHeader header;
static char message[64];
network.read(header,message,sizeof(message));
splitString(message);
}
}
void splitString(char* data) {
char* parameter;
parameter = strtok (data, " ,");
while (parameter != NULL) {
setFunctionelegroep(parameter);
parameter = strtok (NULL, " ,");
}
// Clear the text and serial buffers
for (int x=0; x<64; x++) {
buffer[x]='\0';
}
// Serial.flush();
}
// initialiseer functie. Gewoon i typen en alles gaat naar 0 en middenpositie
void setFunctionelegroep(char* data) {
//------------------- Start functionele groep 1 ---------------------//
if (data[0] == '1') { // funtionele groep
int servoin1 = strtol(data+1, NULL, 10);
//-------------- Groep1 / Servo 1 input/checker/send ----------------//
if (servoin1 >= 1000 && servoin1 <1500){
int serv1 = servoin1 - 1000;
if (serv1 >=0){
serv1 = map(serv1, 0, 255, servmin1, servmax1);
#ifdef DEBUG
Serial.print("Servo 1 is set to: ");
Serial.println(serv1);
#endif
#ifdef Servo01
Serial.println(servoin1);
#endif
servo1.write(serv1);
}
}
//------------- End of groep 1 / Servo 1 control ----------------//
//-------------- Groep1 / Servo 2 input/checker/send ----------------//
if (servoin1 >= 1500 && servoin1 <2000){
int serv2 = servoin1 - 1500;
if (serv2 >=0){
serv2 = map(serv2, 0, 255, servmin2, servmax2);
#ifdef DEBUG
Serial.print("Servo 2 is set to: ");
Serial.println(serv2);
#endif
#ifdef Servo02
Serial.println(servoin1);
#endif
servo2.write(serv2);
}
}
//------------- End of groep 1 / Servo 2 control ----------------//
//-------------- Groep1 / Servo 3 input/checker/send ----------------//
if (servoin1 >= 2000 && servoin1 <2500){
int serv3 = servoin1 - 2000;
if (serv3 >=0){
serv3 = map(serv3, 0, 255, servmin3, servmax3);
#ifdef DEBUG
Serial.print("Servo 3 is set to: ");
Serial.println(serv3);
#endif
#ifdef Servo03
Serial.println(servoin1);
#endif
servo3.write(serv3);
}
}
//------------- End of groep 1 / Servo 3 control ----------------//
//-------------- Groep1 / Servo 4 input/checker/send ----------------//
if (servoin1 >= 2500 && servoin1 <3000){
int serv4 = servoin1 - 2500;
if (serv4 >=0){
serv4 = map(serv4, 0, 255, servmin4, servmax4);
#ifdef DEBUG
Serial.print("Servo 4 is set to: ");
Serial.println(serv4);
#endif
#ifdef Servo04
Serial.println(servoin1);
#endif
servo4.write(serv4);
}
}
//------------- End of groep 1 / Servo 2 control ----------------//
//-------------- Groep1 / Servo 5 input/checker/send ----------------//
if (servoin1 >= 3500 && servoin1 <4000){
int serv5 = servoin1 - 2500;
if (serv5 >=0){
serv5 = map(serv5, 0, 255, servmin5, servmax5);
#ifdef DEBUG
Serial.print("Servo 5 is set to: ");
Serial.println(serv5);
#endif
#ifdef Servo05
Serial.println(servoin1);
#endif
servo5.write(serv5);
}
}
//------------- End of groep 1 / Servo 5 control ----------------//
//-------------- Groep1 / Servo 6 input/checker/send ----------------//
if (servoin1 >= 4000 && servoin1 <4500){
int serv6 = servoin1 - 2500;
if (serv6 >=0){
serv6 = map(serv6, 0, 255, servmin6, servmax6);
#ifdef DEBUG
Serial.print("Servo 6 is set to: ");
Serial.println(serv6);
#endif
#ifdef Servo06
Serial.println(servoin1);
#endif
servo6.write(serv6);
}
}
//------------- End of groep 1 / Servo 2 control ----------------//
//-------------- Groep1 / Servo 9 input/checker/send ----------------//
if (servoin1 >= 5000 && servoin1 <5500){
int serv9 = servoin1 - 5000;
if (serv9 >=0){
serv9 = map(serv9, 0, 255, servmin9, servmax9);
#ifdef DEBUG
Serial.print("Servo 9 is set to: ");
Serial.println(serv9);
#endif
#ifdef Servo07
Serial.println(servoin1);
#endif
servo9.write(serv9);
}
}
//------------- End of groep 1 / Servo 9 control ----------------//
//-------------- Groep1 / Servo 10 input/checker/send ----------------//
if (servoin1 >= 5500 && servoin1 <6000){
int serv10 = servoin1 - 5500;
if (serv10 >=0){
serv10 = map(serv10, 0, 255, servmin10, servmax10);
#ifdef DEBUG
Serial.print("Servo 10 is set to: ");
Serial.println(serv10);
#endif
#ifdef Servo08
Serial.println(servoin1);
#endif
servo10.write(serv10);
}
}
//------------- End of groep 1 / Servo 10 control ----------------//
//-------------- Groep1 / Servo 11 Volume 1 ----------------//
if (servoin1 >= 6000 && servoin1 <6500){
int serv11 = servoin1 - 6000;
if (serv11 >=0){
serv11 = map(serv11, 0, 255, servmin11, servmax11);
#ifdef DEBUG
Serial.print("Servo 11 is set to: ");
Serial.println(serv11);
#endif
#ifdef Servo09
Serial.println(servoin1);
#endif
servo11.write(serv11);
}
}
//------------- End of groep 1 / Volume 1 ----------------//
//-------------- Groep1 / Servo 12 Volume 2 ----------------//
if (servoin1 >= 6500 && servoin1 <7000){
int serv12 = servoin1 - 6500;
if (serv12 >=0){
serv12 = map(serv12, 0, 255, servmin12, servmax12);
#ifdef DEBUG
Serial.print("Servo 12 is set to: ");
Serial.println(serv12);
#endif
#ifdef Servo10
Serial.println(servoin1);
#endif
servo12.write(serv12);
}
}
//------------- End of groep 1 / Volume 2 ----------------//
} // einde functionele groep 1
//------------------- Start functionele groep 2 ---------------------//
if (data[0] == '2') { // funtionele groep
int buttonin1 = strtol(data+1, NULL, 10);
//-------------- Groep2 / buttongroep 1 D22->D28 -----------//
if ( buttonin1 >= 1000 && buttonin1 <1500){
int butto1 = buttonin1 - 1000;
if (butto1 >=0){
#ifdef DEBUG
Serial.print("buttongroep1 code is: ");
Serial.println(butto1);
#endif
////////////////////////////////// D22 ///////////////////////////////
if (butto1 >= 128) {
digitalWrite(Pin22, HIGH);
#ifdef DEBUG
Serial.println("Pin22 = on");
#endif
butto1 = (butto1 - 128);
}
else {
digitalWrite(Pin22, LOW);
}
////////////////////////////////// D23 ///////////////////////////////
if (butto1 >= 64) {
digitalWrite(Pin23, HIGH);
#ifdef DEBUG
Serial.println("Pin23 = on");
#endif
butto1 = (butto1 - 64);
}
else {
digitalWrite(Pin23, LOW);
}
////////////////////////////////// D24 ///////////////////////////////
if (butto1 >= 32) {
digitalWrite(Pin24, HIGH);
#ifdef DEBUG
Serial.println("Pin24 = on");
#endif
butto1 = (butto1 - 32);
}
else {
digitalWrite(Pin24, LOW);
}
////////////////////////////////// D25 ///////////////////////////////
if (butto1 >= 16) {
digitalWrite(Pin25, HIGH);
#ifdef DEBUG
Serial.println("Pin25 = on");
#endif
butto1 = (butto1 - 16);
}
else {
digitalWrite(Pin25, LOW);
}
////////////////////////////////// D26 ///////////////////////////////
if (butto1 >= 8) {
digitalWrite(Pin26, HIGH);
#ifdef DEBUG
Serial.println("Pin26 = on");
#endif
butto1 = (butto1 - 8);
}
else {
digitalWrite(Pin26, LOW);
}
////////////////////////////////// D27 ///////////////////////////////
if (butto1 >= 4) {
digitalWrite(Pin27, HIGH);
#ifdef DEBUG
Serial.println("Pin27 = on");
#endif
butto1 = (butto1 - 4);
}
else {
digitalWrite(Pin27, LOW);
}
////////////////////////////////// D28 ///////////////////////////////
if (butto1 >= 2) {
digitalWrite(Pin28, HIGH);
#ifdef DEBUG
Serial.println("Pin28 = on");
#endif
butto1 = (butto1 - 2);
}
else {
digitalWrite(Pin28, LOW);
}
}
}
//------------- End of groep 2 / buttongroep 1 D22-D28 ------------//
//-------------- Groep2 / buttongroep 2 D29->D35 -----------//
if ( buttonin1 >= 1500 && buttonin1 <2000){
int butto2 = buttonin1 - 1500;
if (butto2 >=0){
#ifdef DEBUG
Serial.print("buttongroep2 code is: ");
Serial.println(butto2);
#endif
////////////////////////////////// D29 ///////////////////////////////
if (butto2 >= 128) {
digitalWrite(Pin29, HIGH);
#ifdef DEBUG
Serial.println("Pin29 = on");
#endif
butto2 = (butto2 - 128);
}
else {
digitalWrite(Pin29, LOW);
}
////////////////////////////////// D30 ///////////////////////////////
if (butto2 >= 64) {
digitalWrite(Pin30, HIGH);
#ifdef DEBUG
Serial.println("Pin30 = on");
#endif
butto2 = (butto2 - 64);
}
else {
digitalWrite(Pin30, LOW);
}
///////////////////////////////// D31 ///////////////////////////////
if (butto2 >= 32) {
digitalWrite(Pin31, HIGH);
#ifdef DEBUG
Serial.println("Pin31 = on");
#endif
butto2 = (butto2 - 32);
}
else {
digitalWrite(Pin31, LOW);
}
////////////////////////////////// D32 ///////////////////////////////
if (butto2 >= 16) {
digitalWrite(Pin32, HIGH);
#ifdef DEBUG
Serial.println("Pin32 = on");
#endif
butto2 = (butto2 - 16);
}
else {
digitalWrite(Pin32, LOW);
}
////////////////////////////////// D33 ///////////////////////////////
if (butto2 >= 8) {
digitalWrite(Pin33, HIGH);
#ifdef DEBUG
Serial.println("Pin33 = on");
#endif
butto2 = (butto2 - 8);
}
else {
digitalWrite(Pin33, LOW);
}
////////////////////////////////// D34 ///////////////////////////////
if (butto2 >= 4) {
digitalWrite(Pin34, HIGH);
#ifdef DEBUG
Serial.println("Pin34 = on");
#endif
butto2 = (butto2 - 4);
}
else {
digitalWrite(Pin34, LOW);
}
////////////////////////////////// D35 ///////////////////////////////
if (butto2 >= 2) {
digitalWrite(Pin35, HIGH);
#ifdef DEBUG
Serial.println("Pin35 = on");
#endif
butto2 = (butto2 - 2);
}
else {
digitalWrite(Pin35, LOW);
}
}
}
//------------- End of groep 2 / buttongroep 2 D29-D35 ------------//
//-------------- Groep2 / buttongroep 3 D36->D42 -----------//
if ( buttonin1 >= 2000 && buttonin1 <2500){
int butto3 = buttonin1 - 2000;
if (butto3 >=0){
#ifdef DEBUG
Serial.print("buttongroep3 code is: ");
Serial.println(butto3);
#endif
////////////////////////////////// D36 ///////////////////////////////
if (butto3 >= 128) {
digitalWrite(Pin36, HIGH);
#ifdef DEBUG
Serial.println("Pin36 = on");
#endif
butto3 = (butto3 - 128);
}
else {
digitalWrite(Pin36, LOW);
}
////////////////////////////////// D37 ///////////////////////////////
if (butto3 >= 64) {
digitalWrite(Pin37, HIGH);
#ifdef DEBUG
Serial.println("Pin37 = on");
#endif
butto3 = (butto3 - 64);
}
else {
digitalWrite(Pin37, LOW);
}
////////////////////////////////// D38 ///////////////////////////////
if (butto3 >= 32) {
digitalWrite(Pin38, HIGH);
#ifdef DEBUG
Serial.println("Pin38 = on");
#endif
butto3 = (butto3 - 32);
}
else {
digitalWrite(Pin38, LOW);
}
////////////////////////////////// D39 ///////////////////////////////
if (butto3 >= 16) {
digitalWrite(Pin39, HIGH);
#ifdef DEBUG
Serial.println("Pin39 = on");
#endif
butto3 = (butto3 - 16);
}
else {
digitalWrite(Pin39, LOW);
}
////////////////////////////////// D40 ///////////////////////////////
if (butto3 >= 8) {
digitalWrite(Pin40, HIGH);
#ifdef DEBUG
Serial.println("Pin40 = on");
#endif
butto3 = (butto3 - 8);
}
else {
digitalWrite(Pin40, LOW);
}
////////////////////////////////// D41 ///////////////////////////////
if (butto3 >= 4) {
digitalWrite(Pin41, HIGH);
#ifdef DEBUG
Serial.println("Pin41 = on");
#endif
butto3 = (butto3 - 4);
}
else {
digitalWrite(Pin41, LOW);
}
////////////////////////////////// D42 ///////////////////////////////
if (butto3 >= 2) {
digitalWrite(Pin42, HIGH);
#ifdef DEBUG
Serial.println("Pin42 = on");
#endif
butto3 = (butto3 - 2);
}
else {
digitalWrite(Pin42, LOW);
}
}
}
//------------- End of groep 2 / buttongroep 3 D35-D42 ------------//
//-------------- Groep2 / buttongroep 4 D43->D49 -----------//
if ( buttonin1 >= 2500 && buttonin1 <3000){
int butto4 = buttonin1 - 2500;
if (butto4 >=0){
#ifdef DEBUG
Serial.print("buttongroep4 code is: ");
Serial.println(butto4);
#endif
////////////////////////////////// D43 ///////////////////////////////
if (butto4 >= 128) {
digitalWrite(Pin43, HIGH);
#ifdef DEBUG
Serial.println("Pin43 = on");
#endif
butto4 = (butto4 - 128);
}
else {
digitalWrite(Pin43, LOW);
}
////////////////////////////////// D44 ///////////////////////////////
if (butto4 >= 64) {
digitalWrite(Pin44, HIGH);
#ifdef DEBUG
Serial.println("Pin44 = on");
#endif
butto4 = (butto4 - 64);
}
else {
digitalWrite(Pin44, LOW);
}
////////////////////////////////// D45 ///////////////////////////////
if (butto4 >= 32) {
digitalWrite(Pin45, HIGH);
#ifdef DEBUG
Serial.println("Pin45 = on");
#endif
butto4 = (butto4 - 32);
}
else {
digitalWrite(Pin45, LOW);
}
////////////////////////////////// D46 ///////////////////////////////
if (butto4 >= 16) {
digitalWrite(Pin46, HIGH);
#ifdef DEBUG
Serial.println("Pin46 = on");
#endif
butto4 = (butto4 - 16);
}
else {
digitalWrite(Pin46, LOW);
}
////////////////////////////////// D47 ///////////////////////////////
if (butto4 >= 8) {
digitalWrite(Pin47, HIGH);
#ifdef DEBUG
Serial.println("Pin47 = on");
#endif
butto4 = (butto4 - 8);
}
else {
digitalWrite(Pin47, LOW);
}
////////////////////////////////// D48 ///////////////////////////////
if (butto4 >= 4) {
digitalWrite(Pin48, HIGH);
#ifdef DEBUG
Serial.println("Pin48 = on");
#endif
butto4 = (butto4 - 4);
}
else {
digitalWrite(Pin48, LOW);
}
////////////////////////////////// D49 ///////////////////////////////
if (butto4 >= 2) {
digitalWrite(Pin49, HIGH);
#ifdef DEBUG
Serial.println("Pin49 = on");
#endif
butto4 = (butto4 - 2);
}
else {
digitalWrite(Pin49, LOW);
}
}
}
//------------- End of groep 2 / buttongroep 5 A8-A14 ------------//
//-------------- Groep2 / buttongroep 5 D43->D49 -----------//
if ( buttonin1 >= 3000 && buttonin1 <3500){
int butto5 = buttonin1 - 3000;
if (butto5 >=0){
#ifdef DEBUG
Serial.print("buttongroep5 code is: ");
Serial.println(butto5);
#endif
////////////////////////////////// A14 ///////////////////////////////
if (butto5 >= 128) {
digitalWrite(Pin14, HIGH);
#ifdef DEBUG
Serial.println("Pin14 = on");
#endif
butto5 = (butto5 - 128);
}
else {
digitalWrite(Pin14, LOW);
}
////////////////////////////////// A13 ///////////////////////////////
if (butto5 >= 64) {
digitalWrite(Pin13, HIGH);
#ifdef DEBUG
Serial.println("Pin13 = on");
#endif
butto5 = (butto5 - 64);
}
else {
digitalWrite(Pin13, LOW);
}
////////////////////////////////// A12 ///////////////////////////////
if (butto5 >= 32) {
digitalWrite(Pin12, HIGH);
#ifdef DEBUG
Serial.println("Pin12 = on");
#endif
butto5 = (butto5 - 32);
}
else {
digitalWrite(Pin12, LOW);
}
////////////////////////////////// A11 ///////////////////////////////
if (butto5 >= 16) {
digitalWrite(Pin11, HIGH);
#ifdef DEBUG
Serial.println("Pin11 = on");
#endif
butto5 = (butto5 - 16);
}
else {
digitalWrite(Pin11, LOW);
}
////////////////////////////////// A10 ///////////////////////////////
if (butto5 >= 8) {
digitalWrite(Pin10, HIGH);
#ifdef DEBUG
Serial.println("Pin10 = on");
#endif
butto5 = (butto5 - 8);
}
else {
digitalWrite(Pin10, LOW);
}
////////////////////////////////// A9 ///////////////////////////////
if (butto5 >= 4) {
digitalWrite(Pin9, HIGH);
#ifdef DEBUG
Serial.println("Pin9 = on");
#endif
butto5 = (butto5 - 4);
}
else {
digitalWrite(Pin9, LOW);
}
////////////////////////////////// A8 ///////////////////////////////
if (butto5 >= 2) {
digitalWrite(Pin8, HIGH);
#ifdef DEBUG
Serial.println("Pin8 = on");
#endif
butto5 = (butto5 - 2);
}
else {
digitalWrite(Pin8, LOW);
}
}
}
//------------- End of groep 2 / buttongroep 5 A8-A14 ------------//
//-------------- Groep2 / buttongroep 6 A15 -----------//
if ( buttonin1 >= 3500 && buttonin1 <4000){
int butto6 = buttonin1 - 3500;
if (butto6 >=0){
#ifdef DEBUG
Serial.print("buttongroep6 code is: ");
Serial.println(butto6);
#endif
////////////////////////////////// D53 ///////////////////////////////
if (butto6 >= 128) {
digitalWrite(Pin15, HIGH);
#ifdef DEBUG
Serial.println("Pin15 = on");
#endif
butto6 = (butto6 - 128);
}
else {
digitalWrite(Pin15, LOW);
}
}
}
//------------- End of groep 2 / buttongroep 5 D53 ------------//
} // einde functionele groep 2
} // void loop
void expanderWrite1(byte _data ) {
Wire.beginTransmission(expander1);
Wire.send(_data);
Wire.endTransmission();
}
void expanderWrite2(byte _data ) {
Wire.beginTransmission(expander2);
Wire.send(_data);
Wire.endTransmission();
}
|