Forum Coding Corner Coding Basics Reply To: Coding Basics

#6793
sakuyarules89

    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() 
    {
    
    //DIM DISPLAY USING POTENTIOMETER
    
    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
    
    //MODE SWITCHING
    
    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)
        {
            digitalWrite(LAT,LOW);
            shiftOut(SER,CLK,LSBFIRST,B01001100);
            shiftOut(SER,CLK,LSBFIRST,B01001101);
            digitalWrite(LAT,HIGH);
        }
    
    if (mode == 3)
        {
            digitalWrite(LAT,LOW);
            shiftOut(SER,CLK,LSBFIRST,B01001001);
            shiftOut(SER,CLK,LSBFIRST,B00101011);
            digitalWrite(LAT,HIGH);
        }
    
    if (mode == 4)
        {
            digitalWrite(LAT,LOW);
            shiftOut(SER,CLK,LSBFIRST,B00101011);
            shiftOut(SER,CLK,LSBFIRST,B00010111);
            digitalWrite(LAT,HIGH);
        } 
    }