Forums Coding Corner Coding Basics

Viewing 4 reply threads
  • Author
    • #6622

      These sketches are referred to in the manuals. They help test functionality and teach concepts. Right-click and download the link to open it in the Arduino IDE. Alternatively, open a new sketch, then click on the link for the sketch. Copy the text into the new sketch and save it. Make sure you don’t miss the last } if copying and pasting.


      The simple blink sketch: DOWNLOAD
      Uses the RTC to show the date and time via the Serial Monitor: DOWNLOAD

      Coding Basics – Blinks SOS: DOWNLOAD
      Coding Basics – Blinks SOS using a for loop: DOWNLOAD


      Simple shiftOut sketch using a switch for mode select and the pot for dimming: DOWNLOAD


      Sensor Array Module Test Script: DOWNLOAD
      Test Script for use with Serial Plotter: DOWNLOAD

      Coding Basics: DHT11: DOWNLOAD
      Coding Basics: LDR: DOWNLOAD
      Coding Basics: Microphone: DOWNLOAD
      Coding Basics: SD Card Write: DOWNLOAD


      RGB Matrix Test Sketch: DOWNLOAD

      Coding Basics – Simple Animation: DOWNLOAD

      • This topic was modified 8 months ago by Martyn.
      • This topic was modified 6 months, 1 week ago by Martyn.
    • #6741

      RTC:99:5: error: expected ‘}’ at end of input
      exit status 1
      expected ‘}’ at end of input

      Is what I am getting when I try to verify and compile. it is showing up for the very last } at line 99.

      also when i try to use the RTC code it asks about the rtclib and that there is no directory.

      • #6749

        ran into that as well. All I did was add extra spaces on each of the comments on the code lines. Between the semi-colon and the //. fixed it for me.

      • #6750

        Hi Cred & Vince,

        Throw another } at the end of the code when you get that error. You may have missed it when you copied the code. A straight copy-paste works fine for me.

        For the RTClib to work you need to download the relevant library. Head to Tools, Manage Libraries… Type RTClib in the search box, then install the RTClib plugin, the one by Adafruit. I should have mentioned this, sorry.

        Vince, that fix sounds strange… The compiler ignores extra spaces, so I’m not sure what is going on there.

        Make sure all the { have matching }. Install the library and everything should work.

        Cheers, M

    • #6788

      I copied the digitizer code (only changed the pins), and have it running. The behavior is not what I expect though, “Mode 1” lights up all the colored LEDs, but none of the digits; “Mode 2” – 4 light all the segments in each digit for all the digits, but none of the LEDs. It looks like it doesn’t matter what I put in my bit, if I put B1xxxxxxx, it turns all the LEDs on, and B0xxxxxxx turns all the segments of all the digits on.

      I realized initially I had one of the shift registers in backward (I thought both were supposed to be pointing to the center of the board), and the backward one got very hot. Do you think this burnt out, and that is why I’m seeing this behavior?

    • #6789

      Sorry to double post, I don’t see an edit button. I found an extra shift register of the same type and tried putting it in, but I’m getting the same behavior.

      • #6790

        That is strange behaviour. Have you checked the underside of the board for any solder bridges? Some of the shift register’s pins might be bridged. Could you post a photo of the front and back of the board? Also, upload the exact sketch so I can have a look at that.

        • #6794

          I’ve tried responding 3 or 4 times now, but it’s not showing up, is there maybe a character limit on the posts that I’m exceeding, or do they need to be approved if they have code? I can send you a direct e-mail if that would be easier.

          • #6799

            Hmm, Sorry about that, I have no idea what could be wrong… I’m new to hosting a forum, so I’ll have to do some digging. Email [email protected] in the meantime and I’ll take a look.

            EDIT: I worked out the problem. I had to manually approve the post. Sorry about that.

    • #6793

      I’ve tried to post this 3 or 4 times now, I’m not seeing it though, so I’ll try once or twice more:

      I did a visual inspection, didn’t find any solder bridges. Then I tried with my multimeter, still didn’t find anything awry. Sorry if this double posts, after I hit submit the post just seemed to disappear, and isn’t showing up even after I refresh.
      Info in pdf form

      Board front
      Front with flash
      Board back

        //Output Pin Variables 
      const int OE = 2;      // Shift Register Output Enable pin
      const int SER = 11;    // Shift Register Serial Data pin
      const int CLK = 12;    // Shift Register Clock pin
      const int LAT = 13;    // Shift Register Latch pin
      //Input Pin Variables
      const int sw1 = A2;    // Switch 1 pin
      const int Pot = A4;    // Potentiometer pin (must be analog pin)
      const int sw2 = A5;    // Switch 2 pin
      //Other Variables
      int mode = 1;     // counter for Mode select
      int swState = 0;     // Holds the current state of the switch
      int lastswState = 0;     // Holds the previous state of the switch
      int potRead = 0;     // Holds the current potentiometer value (0-1024)
      int potDimVal = 0;     // Holds the converted dimming value for output to OE (0-255)
      //Void Setup - runs once at start
      void setup() 
          pinMode(OE, OUTPUT); 
          pinMode(SER, OUTPUT); 
          pinMode(CLK, OUTPUT); 
          pinMode(LAT, OUTPUT); 
          analogWrite(OE, 0);
      //Void Loop - repeats forever
      void loop() 
      potRead = analogRead(Pot); // Reads the pot and assigns potRead the same value
      potDimVal = map(potRead,0,1023,255,0); // maps potRead (0-1023) to potDimVal (255-0)
      analogWrite(OE,potDimVal);   // Sets a PWM value (potDimVal) to the OE pin to set brightness
      swState = digitalRead(sw1);   //read the pushbutton input pin
      if (swState != lastswState)   // compare swState to its previous state, if it changed...
          if (swState == HIGH)   // ...and the current state is HIGH then the button was pressed
                 if (mode < 4)   // if mode is less than the number of modes
                    mode++;   // add 1 to mode, thus changing to the next mode
                 else   // if mode is not less than the number of modes...
                    mode = 1;   // ...set mode to 0 (the first mode)
             delay(5);   // Delay a little bit to avoid bouncing
      lastswState = swState;   // save the current state as the last state
      //Shift Out Digits
      if (mode == 1) // if mode is equal to 1 then execute the following code
              digitalWrite(LAT,LOW); // sets the latch low
              shiftOut(SER,CLK,LSBFIRST,B11101011); // shifts each bit in the given byte to the serial pin, sending the least significant (right most) bit first
              shiftOut(SER,CLK,LSBFIRST,B10001110); // shifts another byte which pushes the last through to the second register
              digitalWrite(LAT,HIGH); // sets the latch high
      if (mode == 2)
      if (mode == 3)
      if (mode == 4)
      • #6806

        I tested your code and it works fine with my test boards. So it must be a fault with the hardware. The fault you described sounds like a problem with the left shift register (U5) as this shift register deals with the LEDs and the Digits. It sounds like one mode is turning on all the outputs and the other mode turns off all the outputs (LEDs turn on when outputs are on and digits turn on when outputs are off). We should test the shift register for faults. Take the chip out, then bend the output pins up (pins 15 & 1-7). Now reseat the chip in the holder and upload the following code:

        const int OE = 2;
        const int SER = 11;
        const int CLK = 12;
        const int LAT = 13;
        void setup() 
            pinMode(OE, OUTPUT); 
            pinMode(SER, OUTPUT); 
            pinMode(CLK, OUTPUT); 
            pinMode(LAT, OUTPUT); 
            analogWrite(OE, 0);
        void loop() 

        testing the shift register outputs

        Use your multimeter to check output 1 (pin 15) reads ~5V. Check the rest of the outputs read 0V. Now change the byte in the code to B0100000 and check the outputs. pin 15 should read 0V, pin 1 should read ~5V and the rest should read 0V. Keep changing the code and checking the readings. If anything looks wrong, try the other shift registers you have.

        Other things to look at are the surface mount resistors and LEDs, which look a bit messy (well done for trying they are tricky). Also, try different ports for each connection, as all the connections to the Digitiser except the pot can be connected to any IO port (make sure you change the code to reflect changes).

        Let me know what you find.

        • #6822

          So I used your code, checked what you explained, everything looked fine; bent the pins back in, uploaded the old code, everything worked.

          -_- Electronics, am I right? One question though: when I turn the potentiometer, the brightness of the LEDs/7-segment doesn’t change, but at a certain low point they turn off, is this right?

          • #6824

            Awesome! Glad it worked! Regarding the Pot, that sounds like you have it connected to a digital pin, not an analog pin. Or, you have OE connected to a non-PWM pin. Possibly… 🙂

          • #6827

            It was the PWM one; works flawlessly now. Thank you again, kind sir!

Viewing 4 reply threads
  • You must be logged in to reply to this topic.