HobbyKing.com New Products Flash Sale
Reply
Thread Tools
Old Feb 18, 2013, 11:39 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
I'll try to make a scematic this week. I have an early shift/graveyard shift so I'm a bit tired. Keep an eye out on this forum. The mega's seem to be no problem. As long as the SPI pins are in the same place and the spacing between te pin is the same. My Mega's are also clone 2540's.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Sign up now
to remove ads between posts
Old Feb 18, 2013, 01:53 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
Found some spare time. Here is a schematic for the receiver unit. De transmitter will follow somewhere the next couple of days.

Danny

Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 18, 2013, 03:53 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,601 Posts
Danny,

This is perfect, thank you.

Pete
blutoh is online now Find More Posts by blutoh
Reply With Quote
Old Feb 26, 2013, 07:01 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
Nummeric LEDs

After some thinkering I decided to go and try again to get the I2C working in combination with the Nordic. In theory it's possible. But first a little test for the nummeric leds. I used D5611's. The program is designed to pick random numbers from 00 to 99. After that it splits the numbers and writes it to two PCF8574(A)P units. In this case an P and an AP with address 000.

For those who want to try it themselves, the code also works with normal leds. Next step: integrating it into the RC receiver.

Danny

PS: A nicer looking board will soon be made.



Code:
/*
Test program for PCF8574 I2C I/O expander
*/

#include <Wire.h>
#define expander1 B0111000
#define expander2 B0100000

int b;

void setup() {
Wire.begin();
  Serial.begin(9600); 
}

void loop() {
b=random(0, 99);
Serial.println(b);

if (b==0){expanderWrite1(B01110111);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11110111);b=b-80;}
if (b>=70){expanderWrite1(B00110100);b=b-70;}
if (b>=60){expanderWrite1(B11100111);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010100);b=b-40;}
if (b>=30){expanderWrite1(B10110110);b=b-30;}
if (b>=20){expanderWrite1(B10110011);b=b-20;}
if (b>=10){expanderWrite1(B00010100);b=b-10;}

//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B01110111);}
if (b==1){expanderWrite2(B00010100);}
if (b==2){expanderWrite2(B10110011);}
if (b==3){expanderWrite2(B10110110);}
if (b==4){expanderWrite2(B11010100);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11100111);}
if (b==7){expanderWrite2(B00110100);}
if (b==8){expanderWrite2(B11110111);}
if (b==9){expanderWrite2(B11110110);}

delay(500);
}

void expanderWrite1(byte _data ) {
Wire.beginTransmission(expander1);
Wire.send(_data);
Wire.endTransmission();
} 

void expanderWrite2(byte _data ) {
Wire.beginTransmission(expander2);
Wire.send(_data);
Wire.endTransmission();
}
Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Feb 26, 2013 at 07:07 AM.
Reply With Quote
Old Feb 26, 2013, 08:40 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
OK, that was easy. The only thing missing in the I2C bus was a little time to send it. A delay(10) was enough to get it going. This revised code is with a working resetbutton and I2C nummeric leds controlled by 2 PCF's. A potentiometer (10K) reads the channel number you want to use. After pushing the reset button (A15 with a pulldown(10K) to GND) the system gets a softreset and reads the analog value. The values are now limited to 80->90 but can easily be changed to channel 01->99. The channel number can be instantly read on the nummeric display, like I said, after reset it becomes the active channel.

Danny

Code:
#include <Servo.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <Wire.h>
#define expander1 B0111000
#define expander2 B0100000

//#define DEBUG // uncomment for feedback through the serialmonitor
#define DynChannel // uncomment for setting dynamic channel select. 
                     // Ananolg pin 13 for potmeter. Reset to use channel
                     // an extra Arduino will be needed (will follow)
                     // RX/TX to serial 1 
#define RESET // do you have want resetbutton? 
                // Stick it on pin A15, and add a 10K pulldown. Led on pin A14

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 = 0; int servmax5 = 255; 
int servmin6 = 0; int servmax6 = 255;
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
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

// 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)
{
  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(6); servo10.attach(7); servo11.attach(10); servo12.attach(11);   

#ifdef DynChannel
  ChannelValue = analogRead (ChannelPin);
  int channel = map(ChannelValue,0,1023,80,90);
  
b = channel;
if (b==0){expanderWrite1(B01110111);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11110111);b=b-80;}
if (b>=70){expanderWrite1(B00110100);b=b-70;}
if (b>=60){expanderWrite1(B11100111);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010100);b=b-40;}
if (b>=30){expanderWrite1(B10110110);b=b-30;}
if (b>=20){expanderWrite1(B10110011);b=b-20;}
if (b>=10){expanderWrite1(B00010100);b=b-10;}

//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B01110111);}
if (b==1){expanderWrite2(B00010100);}
if (b==2){expanderWrite2(B10110011);}
if (b==3){expanderWrite2(B10110110);}
if (b==4){expanderWrite2(B11010100);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11100111);}
if (b==7){expanderWrite2(B00110100);}
if (b==8){expanderWrite2(B11110111);}
if (b==9){expanderWrite2(B11110110);}
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

void loop(void) 
{
#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,80,90);
  b = channel;
  if (channel != channelold){
    if (b==0){expanderWrite1(B01110111);}
if (b>=90){expanderWrite1(B11110110);b=b-90;}
if (b>=80){expanderWrite1(B11110111);b=b-80;}
if (b>=70){expanderWrite1(B00110100);b=b-70;}
if (b>=60){expanderWrite1(B11100111);b=b-60;}
if (b>=50){expanderWrite1(B11100110);b=b-50;}
if (b>=40){expanderWrite1(B11010100);b=b-40;}
if (b>=30){expanderWrite1(B10110110);b=b-30;}
if (b>=20){expanderWrite1(B10110011);b=b-20;}
if (b>=10){expanderWrite1(B00010100);b=b-10;}

//expanderWrite2(B00001000); // dot
if (b==0){expanderWrite2(B01110111);}
if (b==1){expanderWrite2(B00010100);}
if (b==2){expanderWrite2(B10110011);}
if (b==3){expanderWrite2(B10110110);}
if (b==4){expanderWrite2(B11010100);}
if (b==5){expanderWrite2(B11100110);}
if (b==6){expanderWrite2(B11100111);}
if (b==7){expanderWrite2(B00110100);}
if (b==8){expanderWrite2(B11110111);}
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
        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
        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
        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
/*        
int motorgeluid = map(serv4,55,190,0,25);
    if (motorgeluid == 0){Serial1.write('9');}
    if (motorgeluid == 1){Serial1.write('8');}
    if (motorgeluid == 2){Serial1.write('7');}    
    if (motorgeluid == 3){Serial1.write('6');}    
    if (motorgeluid == 4){Serial1.write('5');}    
    if (motorgeluid == 5){Serial1.write('4');}    
    if (motorgeluid == 6){Serial1.write('3');}    
    if (motorgeluid == 7){Serial1.write('2');}    
    if (motorgeluid == 8){Serial1.write('1');}
    if (motorgeluid == 9){Serial1.write('0');}
    if (motorgeluid == 10){Serial1.write('1');}
    if (motorgeluid == 11){Serial1.write('2');}
    if (motorgeluid == 12){Serial1.write('3');}
    if (motorgeluid == 13){Serial1.write('4');}
    if (motorgeluid == 14){Serial1.write('5');}
    if (motorgeluid == 15){Serial1.write('6');}
    if (motorgeluid == 16){Serial1.write('7');}
    if (motorgeluid == 17){Serial1.write('8');}
    if (motorgeluid == 18){Serial1.write('9');}
    */
    servo4.write(serv4); 
        
      }
    }
//-------------   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
        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
        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
        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
        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();
}
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 26, 2013, 12:02 PM
Registered User
Joined Dec 2012
117 Posts
You might consider doing an LCD screen, something like a 16x2 or 20x2 or 20x4 or whatever... You can get these in i2c bus or serial bus. I like the ones from Newhaven, which I purchased through http://www.digikey.com . I've done the 7-segment LED thing with an i2c port exander (MCP23017) on my MonsterShield ( http://www.hauntsoft.com ) but wished I had done an LCD screen instead. I'm doing a 16x2 LCD screen on my Arduino RC transmitter now and I've found it to be extremely useful.

I've now worked with several different i2c devices: MCP23017, MCP2008, DS1803, DS1844, and several different i2c EEPROMS and FRAM chips. One thing I've noticed is that different i2c devices may require more time between transmissions than others. The EEPROMs took longer and needed something like 5-10 ms delays between writes. The FRAM ones worked faster.
Skystream is offline Find More Posts by Skystream
Reply With Quote
Old Feb 26, 2013, 12:44 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
Skystream,
Perhaps you didn't see the transmitter on the first page. There is a 40x2 LCD in the transmitter. Not controlled by I2C but RX/TX because it checks quit a lot and I have quit a few custom characters in it. It also has a debug option for the transmitter and has several different menu's. Each boat has it's own functions and menu. The transmitter is not the basic version of my arduino-control. I'm creating this basic version so everyone can use it without having to learn how to program. A LCD would be a little overkill in the boat.

Back to the receiver. Here is a I2C PCB for the reset/Led/channel option. It is a beta test version, but the breadboard functions allright.
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 26, 2013, 06:48 PM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,601 Posts
Hi Danny,

Have you given any thought yet to the transmitter control layout? Like, dual throttle control sliders or sticks, what kind of control for the the bow thruster, location of swithches and buttons, etc. etc.

Pete
blutoh is online now Find More Posts by blutoh
Reply With Quote
Old Feb 27, 2013, 02:48 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
First a little standard test version/PCB like the receiver side. I allready have a spiderweb version of the transmitter (see page 1, firstpost). It's just pins in the arduino. I've build that one as prove of concepts with a few extras. The receiver version was also a pin in arduino version. I've sailed my test boat (a small Robbe Kormoran) about a year or so with that setup, tweaking it every time to make the protocol better. It had a fully working crane, lights (in different groups), smoke, radar, sounds, functioning tow hook/entering hook, motor, rudder and bowthruster (and a leaking drive shaft).



When the PCB version is fininshed and posted with the reset/channel select/led-PCB functioning, then then basic version is ready for everyone the build for themselves. Then everyone can build their own version and setup, choosing the number of channels with the defines. I'll try to make a manual for it on how to build and basic setup.

I have a old Futaba F14 transmitter which will receive the arduino-board. I allready altered the layout. Left sticks and extra up/down stick are for a crane and the right stick has an extra knob for the bowthruster. In the top module holes I can put the switches and some extra pots. It looks a bit hopeless, bit it will be OK when finished.



Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Old Feb 27, 2013, 04:01 AM
Registered User
Deckie's Avatar
Australia, WA, Garden Island
Joined Nov 2010
464 Posts
It's good to see you worked out the I2C issues, and interesting to see that a small delay is required. I haven't run across that, but then i'm not continuously polling the bow Arduino for data. I'm gonna go and see If I can run into the same issue now
Deckie is offline Find More Posts by Deckie
Reply With Quote
Old Feb 27, 2013, 04:13 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
The delay is only needed when I change the channel number, which work with I2C expanders. The normal operation has no delays. I'm still trying to get it to work with a minimal or no delay. Normal I2C doesn't need a delay. It's just to give the I2C bus some time before the Nordic NRF's start communicating with the arduino.

Do you also have an arduino control system? I'm curious how others have done this. How many functions can it handle, what kind of protocol, what do you use as transmitter/receiver? I like your thermal/flood system.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Feb 27, 2013 at 04:23 AM.
Reply With Quote
Old Feb 27, 2013, 09:25 AM
Registered User
Joined Dec 2012
117 Posts
Quote:
Originally Posted by Dutchraptor View Post
Skystream,
Perhaps you didn't see the transmitter on the first page. There is a 40x2 LCD in the transmitter. Not controlled by I2C but RX/TX because it checks quit a lot and I have quit a few custom characters in it. It also has a debug option for the transmitter and has several different menu's. Each boat has it's own functions and menu. The transmitter is not the basic version of my arduino-control. I'm creating this basic version so everyone can use it without having to learn how to program. A LCD would be a little overkill in the boat.

Back to the receiver. Here is a I2C PCB for the reset/Led/channel option. It is a beta test version, but the breadboard functions allright.
My bad. I had seen the images before on another day. Also did not realize the 7 segments were for the boat. I'm actually doing RX/TX on my lcd as well even though it supports i2c.
Skystream is offline Find More Posts by Skystream
Reply With Quote
Old Feb 28, 2013, 04:58 AM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
Final Version Receiver Shield

Hi guys,
Today I present to you the final version of the basic receiver shield. With this post there are also the final versions (with a few bugs worked out) of the Shields themself, the channelselect/reset expansion, the arduino sketch fot the receiver unit and a test program to find out which pins are which on the 7 segment lednumbers. The pinnumbers from the led tester can be copied to the receiver sketch. You need to place them in 2 places. Scrolling down the sketch, and you will easily spot them. I can't make that a standard since there are quit aa few different versoin of those led numbers. The receivers sketchs still has the option for a fixed channel. Comment the define and you only have channel 80. There is also an option added for a range af channels with which you van choose from with the 10K pot. I have chosen 80->99, but you can change it between 01->99. To big a range makes it harder to select the channel when the pot isn't of a high quality. All the pull-down resistors on the i/o pins are 10k. The led resistot has a value of 1k, but can change when using other leds. Furthermore there are 5 7805 voltage regulators for the servo's, 1 for each 2 servo's. I've done this to have as little as possible strain on the arduino ports. The test shield for the receivershield is nothing more then 36 leds and small resistors to make sure the leds don't burn out. I've use 1k version, but around 500Ohm works too. All the parts for the expansion shield are named in the parts PDF. The expansion is for 2 7-segment lednumbers, a reset button and a 10k pot for channel select. It uses one PCF8574P and one PCF8574AP ic.

Test are done for both units. Next week I will be making the basic TransmitterShield. It's not more complicated then this one and has the same expansion unit. Have fun when trying to build one for yourself. More expansions will follow to make it more versatile.

And to be complete, a reminder from earlier post: All the info on how to use them + library came from:
http://arduino-info.wikispaces.com/N...1-2.4GHz-HowTo

The NRF's use 7 wires. They say it uses 3.3 volt, but have them on the 5volt. I think there is a regulator on these things, but please test on 3.3 volt before using 5volt.

MEGA/328
NRFpin 1 => gnd/GND
NRFpin 2 = > 3.3V!!!/3.3V!!!
NRFpin 3 = > 8/8
NRFpin 4 = > 9/9
NRFpin 5 = > 52/13
NRFpin 6 = > 51/11
NRFpin 7 = > 50/12
NRFpin 8 = > NC/NC

See page 1 for the version without the ledtest shield/pin version

Danny




Code:
/*
zowel de aan als uit code sturen voor de pins. Verzamelen in de code van de groep
en daarna verzenden aan het einde van de groep met een old-checker.
*/

#include <Servo.h>
#include <RF24Network.h>
#include <RF24.h>
#include <SPI.h>
#include <Wire.h>
#define expander1 B0111000
#define expander2 B0100000

const int chlow = 80; // set lowest channel number
const int chhi = 99; // set highest channel number

//#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
                     // an extra Arduino will be needed (will follow)
                     // RX/TX to serial 1 
#define RESET // do you have want resetbutton? 
                // Stick it on pin A15, and add a 10K pulldown. Led on pin A14

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
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

// 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
  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

  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

void loop(void) 
{
#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();
}
Code:
/*
Test program for PCF8574 I2C I/O expander 7 segment display
*/

#include <Wire.h>

#define Numbers // count from 0->9
//#define Seperate // just show the seperate leds
#define expander B0111000
//#define expander B0100000

void setup() {
Wire.begin();
}

void loop() {
#ifdef Seperate
expanderWrite(B10000000); // Pin 1
delay(500);
expanderWrite(B01000000); // Pin 2
delay(500);
expanderWrite(B00100000); // Pin 3
delay(500);
expanderWrite(B00010000); // Pin 4
delay(500);
expanderWrite(B00001000); // Pin 5
delay(500);
expanderWrite(B00000100); // Pin 6
delay(500);
expanderWrite(B00000010); // Pin 7
delay(500);
expanderWrite(B00000001); // Pin 8
delay(500);
#endif
  
#ifdef Numbers
expanderWrite(B01111110); // 0
delay(500);
expanderWrite(B00010010); // 1
delay(500);
expanderWrite(B10111100); // 2 
delay(500);
expanderWrite(B01110110); // 3
delay(500);
expanderWrite(B11010010); // 4
delay(500);
expanderWrite(B11100110); // 5
delay(500);
expanderWrite(B11101110); // 6
delay(500);
expanderWrite(B00110010); // 7
delay(500);
expanderWrite(B11111110); // 8
delay(500);
expanderWrite(B11110110); // 9
delay(500);
#endif
}

void expanderWrite(byte _data ) {
Wire.beginTransmission(expander);
Wire.send(_data);
Wire.endTransmission();
}
Dutchraptor is online now Find More Posts by Dutchraptor
Last edited by Dutchraptor; Feb 28, 2013 at 05:05 AM. Reason: added PDF's
Reply With Quote
Old Feb 28, 2013, 09:48 AM
---o-O-o---
blutoh's Avatar
United States, NJ, Livingston
Joined Mar 2012
1,601 Posts
Danny,

Excellent! I will start digesting this bit by bit. The code looks less complex than I had imagined it would. For the 10k channel selctor pot, are you using one that has detents, like click steps, to fix the channel values, or is it free turning?

Pete
blutoh is online now Find More Posts by blutoh
Reply With Quote
Old Feb 28, 2013, 04:35 PM
Registered User
Dutchraptor's Avatar
The Netherlands, ZH, Hoogvliet
Joined Jul 2008
297 Posts
Just a very cheap free running 10K pot (bought 20 very cheap from ebay). With detents would be nicer.

Danny
Dutchraptor is online now Find More Posts by Dutchraptor
Reply With Quote
Reply


Thread Tools

Similar Threads
Category Thread Thread Starter Forum Replies Last Post
New Product Open Source Lights - Arduino based RC Light Controller LukeZ DIY Electronics 42 Jun 30, 2014 09:10 PM
Discussion Arduino Uno Based Flight Controller? alexgator Multirotor Electronics 4 Feb 15, 2013 12:49 AM
Discussion I want to auto controlled RC helicopter with arduino+wmp+nunchuk parkjungho Electric Heli Talk 3 Jun 21, 2011 02:58 PM
Discussion Arduino project to build autopilot controlled RC plane! Ecibob Electric Plane Talk 2 Apr 25, 2011 10:17 AM