!!

Not Registered?

Welcome!  Please register to view all of the new posts and forum boards - some of which are hidden to guests.  After registering and gaining 10 posts you will be able to sell and buy items on our N'porium.

If you have any problems registering, then please check your spam filter before emailing us.  Hotmail users seem to find their emails in the Junk folder.


Thanks for reading,
The NGF Staff.

Author Topic: Arduino - EEK!!  (Read 555 times)

0 Members and 1 Guest are viewing this topic.

Offline themadhippy

  • Trade Count: (0)
  • Full Member
  • ***
  • Posts: 315
  • Country: gb
    • Awards
Re: Arduino - EEK!!
« Reply #15 on: September 01, 2017, 01:59:23 pm »
If im reading the spec correct you want the switches on board A to control relays on board B  and board B switches to control  relays on board A.
To read the 8 switches wire then to inputs 2-9  and
Code: [Select]
byte onpins = (PIND & 0xFC) | (PINB & 0x03); (stolen from somewhere)
should  return a binary number  representing there state, so all on will give 11111111 and all off 00000000 .
     Depending how  your sending the data you maybe able to send it as  the raw binary  or need to convert to a decimal value.
 At the other end wire the 8 outputs from pin 10 to 17 , convert the decimal back to binary if necessary and name the variable onpins  and run something along the lines of

Code: [Select]
int myPins[] = {10,11, 12. 13, 14, 15, 16, 17};


void setup() {
   for (int ii = 0; ii <= 7; ii++) {
      pinMode(myPins[ii],OUTPUT);
      digitalWrite(myPins[ii],LOW);
   }
}

void loop() {
   for (int ii = 0; ii <= 7; ii++) {
      if (onPins & (B10000000 >> ii)) {
         digitalWrite(myPins[ii],HIGH);
      }
      else {
         digitalWrite(myPins[ii],LOW);
      }
   }
}
(stolen from http://www.fiz-ix.com/2013/02/using-bytes-and-bitmasks-to-control-multiple-arduino-digital-outputs/ )
« Last Edit: September 01, 2017, 02:32:41 pm by themadhippy »

Offline Only Me

  • Reader of The Manual
  • NGF Technician
  • Trade Count: (+13)
  • Full Member
  • ****
  • N Gauge Society Number: 23206
  • Posts: 5503
  • Country: gb
  • Gender: Male
  • Exhibition Layout - Tormouth
    • Northants & Cambs Area Group of the NGS
    • Awards
Re: Arduino - EEK!!
« Reply #16 on: September 01, 2017, 03:31:00 pm »
Unforunately, the ethernet card uses pins 10-13

also I have 5 switches and 3 relays, thanks for having  a look but I've no idea what you mean :D



Offline themadhippy

  • Trade Count: (0)
  • Full Member
  • ***
  • Posts: 315
  • Country: gb
    • Awards
Re: Arduino - EEK!!
« Reply #17 on: September 01, 2017, 04:50:44 pm »
Quote
also I have 5 switches and 3 relays
even easier,wire the 5  switches to the 5 analogue inputs  configured as digital inputs and read  all the pins at once with command  PINC, bit of code to direct the relevant switch presses to  outputs on say pins 6,7  and 8 yer done :smiley-laughing:
« Last Edit: September 01, 2017, 08:00:35 pm by themadhippy »

 

Please Support Us!
December Goal: £55.00
Due Date: Dec 31
Total Receipts: £55.00
Below Goal: £0.00
Site Currency: GBP
100% 
December Donations


Advertise Here