From Insensitive Crow, 2 Months ago, written in C.
This paste will run down the curtain in 1 Second.
Embed
  1. /*
  2.   Serial Twistedsha=ck Control
  3.  */
  4.  
  5. const int RLYPinA= 3; // the pin that Relay A is attached to
  6. const int RLYPinB= 4; // the pin that Relay B is attached to
  7. const int RLYPinC= 5; // the pin that Relay C is attached to
  8. const int RLYPinD= 6; // the pin that Relay D is attached to
  9. const int RLYPinE= 7; // the pin that Relay E is attached to
  10. const int RLYPinF= 8; // the pin that Relay f is attached to
  11.  
  12. int incomingByte;     // a variable to read incoming serial data into
  13.  
  14. void setup() {
  15.   // initialize serial communication:
  16.   Serial.begin(9600);
  17.  
  18.   // initialize the relay pins as outputs:
  19.   pinMode(RLYPinA, OUTPUT);
  20.   pinMode(RLYPinB, OUTPUT);
  21.   pinMode(RLYPinC, OUTPUT);
  22.   pinMode(RLYPinD, OUTPUT);
  23.   pinMode(RLYPinE, OUTPUT);
  24.   pinMode(RLYPinF, OUTPUT);
  25.  
  26.   // initialize the relay pins as to OFF (logic is inverted):
  27.   digitalWrite(RLYPinA, HIGH);
  28.   digitalWrite(RLYPinB, HIGH);
  29.   digitalWrite(RLYPinC, HIGH);
  30.   digitalWrite(RLYPinD, HIGH);
  31.   digitalWrite(RLYPinE, HIGH);
  32.   digitalWrite(RLYPinF, HIGH);
  33.  
  34.  
  35. }
  36.  
  37. void loop() {
  38.   // see if there's incoming serial data:
  39.   if (Serial.available() > 0) {
  40.     incomingByte = Serial.read();
  41.  
  42.     if (incomingByte == 'a') {
  43.       digitalWrite(RLYPinA, HIGH);
  44.     }
  45.  
  46.     if (incomingByte == 'A') {
  47.       digitalWrite(RLYPinA, LOW);
  48.     }
  49.  
  50.     if (incomingByte == 'b') {
  51.       digitalWrite(RLYPinB, HIGH);
  52.     }
  53.  
  54.     if (incomingByte == 'B') {
  55.       digitalWrite(RLYPinB, LOW);
  56.     }
  57.  
  58.     if (incomingByte == 'c') {
  59.       digitalWrite(RLYPinC, HIGH);
  60.     }
  61.  
  62.     if (incomingByte == 'C') {
  63.       digitalWrite(RLYPinC, LOW);
  64.     }
  65.  
  66.     if (incomingByte == 'd') {
  67.       digitalWrite(RLYPinD, HIGH);
  68.     }
  69.  
  70.     if (incomingByte == 'D') {
  71.       digitalWrite(RLYPinD, LOW);
  72.     }
  73.  
  74.     if (incomingByte == 'e') {
  75.       digitalWrite(RLYPinE, HIGH);
  76.     }
  77.  
  78.     if (incomingByte == 'E') {
  79.       digitalWrite(RLYPinE, LOW);
  80.     }
  81.  
  82.     if (incomingByte == 'f') {
  83.       digitalWrite(RLYPinF, HIGH);
  84.     }
  85.  
  86.     if (incomingByte == 'F') {
  87.       digitalWrite(RLYPinF, LOW);
  88.     }
  89.   }
  90. }
  91. //EOF
  92.