Forums Radionics LSD03 arduino sketch

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #1057415
    General Lighting
    Moderator

      I can’t put this on the blog as it is too long; and being source code splitting it up could introduce errors if anyone wants to reuse it. It isn’t the best code either (there are still leftovers from the LSD01 sketch it was derived from) but it works 😉

      you will need these libraries

      https://github.com/rklancer/ansiterm
      https://github.com/thomasfredericks/Bounce-Arduino-Wiring

      if you want the retro font it is here

      http://bjh21.me.uk/bedstead/

      Quote:
      /*
      LSD 03 : using 6 in / out velleman card
      and arduino
      to control LSD 02 analogue circuits
      with serial console opt

      2014-06-29 Alex The Engineer
      rtn telecommunicatie
      VFRmedia Ipswich, UK
      */

      const int sigPins[6] = {2,3,4,5,6,7};
      const int relayPins[6] = {8,9,10,11,12,13};

      // this ia LDR brightness if telephone strobe is on

      const int strobeVal = 700 ;
      const int sigDelay = 20 ; // button deley

      // waakkat

      #define FATCAT 1500
      #define SIAMEES 375
      #define KITTEN 50

      // max pins (1 more than array bounds)
      #define TOTALPINS 6

      // beware this lib name is changed

      #include
      #include

      // global declarations & vars

      Bounce sig[TOTALPINS] = {Bounce(),Bounce(),Bounce(),Bounce(),Bounce(),Bounce()} ; // array of bounce objects
      Ansiterm ansi; // console

      int incomingbyte = 0;
      int relayState[6] = { LOW, LOW, LOW, LOW, LOW, LOW};
      int sigChange[6] = { LOW, LOW, LOW, LOW, LOW, LOW };
      int sigState[6] = { HIGH, HIGH, HIGH, HIGH , HIGH, HIGH }; // as these are pulled up (active low)
      int ttyUpdate = HIGH ;
      int iptChange = HIGH ; // so the display always updates even if some faders already are up

      unsigned long previousMillis = 0;
      unsigned long lastTime = 0 ;

      // waakkat

      int miauw= LOW ;
      long miauwInterval = FATCAT ; // meower

      // redlight pfl telephone

      int redlight = LOW;
      int pfl = LOW; // green ()
      int currpfl = LOW; // for auto force green when red
      int telephone = LOW ;
      int amber = LOW ;

      char *sigNames[]={ “RED”, “PFL”, “PC2”, “JNG”, “GRM”, “TEL” } ;
      int sigbColours[6] = { RED, BLUE, YELLOW, YELLOW, GREEN, WHITE };
      int sigfColours[6] = { YELLOW, YELLOW, RED, RED, RED, BLUE };
      char *rlyNames[]={ “MIC”, “PFL”, “AM1”, “AM2”, “SR1”, “RNG” };
      int rlybColours[6] = { RED, BLUE, YELLOW, YELLOW, GREEN, BLUE};
      int rlyfColours[6] = { YELLOW, WHITE, BLUE, BLUE, BLUE, WHITE};

      void setup()
      {

      Serial.begin(38400);

      for (int i=0 ; i < TOTALPINS ; i++)
      {

      pinMode(sigPins, INPUT);
      sig
      =Bounce();
      sig
      .attach(sigPins);
      sig
      .interval(sigDelay);
      pinMode(relayPins
      , OUTPUT);
      }

      setConsole(“*rtn telecommunicatie:LSD03 1.00:ready “);
      getSignals(TOTALPINS);

      // but force iptchange so console updates
      // and catch any active signals on first run

      for ( int i=0 ; i < TOTALPINS ; i++)
      {
      relayState
      =sigState;
      }

      iptChange=HIGH;

      relayEmit(TOTALPINS);
      updateConsole(TOTALPINS);

      }

      void loop()
      {

      ttyUpdate = LOW ;
      getSignals(TOTALPINS);

      redlight = sigState[0];

      if (sigState[1] && sigChange[1]) {
      pfl = !pfl ;
      currpfl = pfl;

      }

      if (redlight) {
      pfl = LOW;
      miauwInterval = SIAMEES ;

      }
      else {
      pfl = currpfl;
      miauwInterval = FATCAT ;

      }

      relayState[0] = redlight ;
      relayState[1] = pfl ;
      relayState[2] = sigState[2];
      relayState[3] = sigState[3];
      relayState[4] = sigState[4];
      relayState[5] = sigState[5];

      ttyUpdate = iptChange ;

      // guard cat will meow to the console (tty)

      unsigned long currentMillis = millis();

      if (currentMillis – previousMillis > miauwInterval) {
      previousMillis = currentMillis;
      miauw = !miauw ;
      // relayState[5] = miauw ;

      ttyUpdate = HIGH ;
      }

      relayEmit(TOTALPINS);

      // update if there is a button change or a miauw

      // ttyUpdate = ttyUpdate | iptChange ;

      while (ttyUpdate)
      {
      updateConsole(TOTALPINS);
      ttyUpdate = LOW;
      }

      }

      // Functions now go here at end of sketch

      void setConsole(char* message)
      {
      ansi.setBackgroundColor(BLACK);
      ansi.eraseScreen();//works
      ansi.home();
      ansi.setBackgroundColor(GREEN);
      ansi.setForegroundColor(BLACK);
      Serial.print(message);
      }

      void relayEmit(int maxPins)
      {
      for (int i = 0 ; i < (maxPins) ; i++)
      {
      digitalWrite(relayPins
      ,relayState);

      }
      }

      void getSignals(int maxPins)
      {
      iptChange = LOW ;

      for (int i = 0 ; i < (maxPins) ; i++)
      {
      sigChange
      = sig.update();
      iptChange = iptChange | sigChange
      ; // have any changed?
      sigState
      = !(sig.read());
      }
      }

      void updateConsole(int maxPins)
      {
      if (iptChange) {

      for (int i=0 ; i < (maxPins) ; i++)
      {
      ansi.xy(6+(i*5),3);
      if (sigState
      ) {
      ansi.setForegroundColor(sigfColours
      );
      ansi.setBackgroundColor(sigbColours
      );
      Serial.print(sigNames
      );
      }
      else {
      ansi.setForegroundColor(WHITE);
      ansi.setBackgroundColor(BLACK);
      Serial.print(” “);
      }
      ansi.xy(6+(i*5),5);
      if (relayState
      ) {
      ansi.setForegroundColor(rlyfColours
      );
      ansi.setBackgroundColor(rlybColours
      );
      Serial.print(rlyNames
      );
      }
      else {
      ansi.setForegroundColor(WHITE);
      ansi.setBackgroundColor(BLACK);
      Serial.print(” “);
      }
      }

      }

      ansi.xy(34,1);
      if (miauw) {

      ansi.setForegroundColor(BLUE);
      ansi.setBackgroundColor(YELLOW);
      Serial.write(“miauw”);
      }
      else {

      ansi.setForegroundColor(WHITE);
      ansi.setBackgroundColor(GREEN);
      Serial.write(” “);
      }

      }

    Viewing 1 post (of 1 total)
    • You must be logged in to reply to this topic.

    Forums Radionics LSD03 arduino sketch