Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Controlling Leds & Valves same time PortArrayModule
#1
Hi Josh:

For the PortArrayModule
I have created this function to control LEDs and Valves in same command:

Code:
     case 'M': // Set LED and Valve Array Bits (1 = max brightness, open ; 0 = off, close)
       newValue = readByteFromSource(opSource);
       for (int i = 0; i < 8; i++) {
         if (i < 4)  { // First 4 bits are for LEDS
           if (bitRead(newValue, i)) {
             analogWrite(ledChannels[i], 255);
           } else {
             analogWrite(ledChannels[i], 0);
           }
         } else {  // Last 4 bits are for Valves
           if (bitRead(newValue, i)) {
             digitalWrite(valveChannels[i-4], HIGH);
           } else {
             digitalWrite(valveChannels[i-4], LOW);
           }  
         }
       }


Is this the way to go ?
I only found that there is no chance to have 256 possible states assigned (only 255 commands can be sent through LoadSerialMessages) so I guess there would be a "forbidden" case where every LED and Valve are ON at the same time.

Thanks Again
Reply


Forum Jump: