diff --git a/eigener_ctrl/arduino_sketch/arduino_sketch.ino b/eigener_ctrl/arduino_sketch/arduino_sketch.ino index 1e2dc88..7d0173f 100644 --- a/eigener_ctrl/arduino_sketch/arduino_sketch.ino +++ b/eigener_ctrl/arduino_sketch/arduino_sketch.ino @@ -1,206 +1,136 @@ -//Pin Assignments (You should change these) -const int CLK = 9; //Connected to TPIC pin 13: SRCLK (aka Clock) -const int LATCH = 10; //Connected to TPIC pin 12: RCLK (aka Latch/load/CS/SS...) -const int OE = 11; //Connected to TPIC pin 9: OE (Output Enable) -const int DOUT = 12; //Connected to TPIC pin 3: SER (aka MOSI) +#define CLK 2 //Connected to TPIC pin 13: SRCLK (aka Clock) +#define LATCH 3 //Connected to TPIC pin 12: RCLK (aka Latch/load/CS/SS...) +#define DOUT 4 //Connected to TPIC pin 3: SER (aka MOSI) +#define SEG_0 A0 +#define SEG_1 A1 +#define SEG_2 A2 +#define SEG_3 A3 +#define SEG_4 A4 +#define SEG_5 A5 +#define SEG_6 11 +#define SEG_7 12 -//Number Patterns (0-9) -//***Drains 0-7 must be connected to segments A-DP respectively*** -const byte numTable[] = -{ - B11111100, - B01100000, - B11011010, - B11110010, - B01100110, - B10110110, - B10111110, - B11100000, - B11111110, - B11110110 -}; +#define FET_COUNT 8 +#define BYTE_PER_FET 6 -//Global Variables -int numDevices = 1; //The number of x-digit display modules you plan to use -int maxDisplays = 3; //The maximum displays that could be accommodated (see note 1) -int maxDigits = 3; //The maximum digits you plan on displaying per display module (each SR can handle a max of 8 digits) -int SRData[3][3]; //The storage location for the digit information. We must specify a fixed array at compile time (see note 2) -boolean debug = true; //Change to true to print messages -int delayTime = 1000; //Optional (just for demonstrating multiplexing) +volatile uint8_t data[FET_COUNT][BYTE_PER_FET]; +long dataMillis = 0; +uint8_t dataDemoStep = 0; -/* - Notes -1. It is recommended to use an external power supply to avoid oversource/sinking the microcontroller - or if you need to power high voltage, high current displays. This code will turn on/off all segments in a digit for ***each*** display. - So, if using 2x 3-digit displays all displaying an 8 + DP, the max consumption will be: - 20mA (desired forward current) * 8 (segments that are on) * 2 (displays showing identical info) = 320mA -2. The first dimension should equal maxDisplays. The second dimension should equal the number of digits -*/ +void setup() { + Serial.begin(115200); -void setup() -{ - Serial.begin(9600); - - //Set pin modes pinMode(CLK,OUTPUT); pinMode(LATCH,OUTPUT); pinMode(DOUT, OUTPUT); - pinMode(OE, OUTPUT); + pinMode(SEG_0, OUTPUT); + pinMode(SEG_1, OUTPUT); + pinMode(SEG_2, OUTPUT); + pinMode(SEG_3, OUTPUT); + pinMode(SEG_4, OUTPUT); + pinMode(SEG_5, OUTPUT); + pinMode(SEG_6, OUTPUT); + pinMode(SEG_7, OUTPUT); - //7-Segment Display Init - digitalWrite(OE,LOW); //Enables SR Operation initializeSRData(); //Prepares SR and clears data on serial line - //Test - setDigit(0,0,4,true); - setDigit(0,1,5,true); - setDigit(0,2,6,true); } -void loop() -{ +void loop() { + + if(millis() - dataMillis > 10) { + static uint8_t counterFet = 0; + static uint8_t counterDigit = 0; + static uint8_t counterBit = 0; + + for(int fet=0; fet 7) { + counterBit = 0; + counterDigit++; + + if(counterDigit > 5) { + counterFet++; + counterDigit = 0; + counterFet %= FET_COUNT; + } + } + + + + dataMillis = millis(); + } + + refreshDisplay(); //Cycles through all displays and digits } -//==========BEGIN SR Functions========== -void initializeSRData() -{ - //Display Scanner (Iterates through each display module) - digitalWrite(LATCH,LOW); //Tells all SRs that uController is sending data +void initializeSRData() { + + digitalWrite(LATCH,HIGH); //Tells all SRs that uController is sending data - for(int dispID = 0; dispID < maxDisplays; dispID++) - { - //Digit Scanner (Iterates through each SR (digit) in a display module) - for(int digit = 0; digit < maxDigits; digit++) - { - //Clears any garbage on the serial line - shiftOut(DOUT,CLK,LSBFIRST,0); //Shift out 0s to all displays - SRData[dispID][digit] = 0; //Stores a 0 for each digit so its completely off - } + for(int digit = 0; digit < BYTE_PER_FET; digit++) { + shiftOut(DOUT, CLK, LSBFIRST,0); } - digitalWrite(LATCH,HIGH); //Tells all SRs that uController is done sending data + + digitalWrite(LATCH,LOW); //Tells all SRs that uController is done sending data } -void printSRData() -{ - if(!debug) - return; - Serial.println("Printing SR Data..."); - //Display Scanner - for(int dispID = 0; dispID < maxDisplays; dispID++) - { - Serial.print("Display # "); - Serial.println(dispID); - //Digit Scanner - for(int digit = 0; digit < maxDigits; digit++) - { - Serial.print("Digit "); - Serial.print(digit); - Serial.print(": "); - Serial.println(SRData[dispID][digit],BIN); - } - Serial.println(); - } -} - -void setDigit(int dispID, int digit, int value, boolean dp) -{ - //Parameter checker - if(dispID < 0 || dispID >= numDevices) - { - Serial.println("dispID OoB!"); //OoB = Out of bounds - return; - } - - if(digit < 0 || digit > maxDigits) - { - Serial.println("digit OoB!"); - return; - } - - if(value < 0 || value > 9) - { - Serial.println("Invalid value!"); - return; - } - - value = numTable[value]; - - //Toggle dp if needed - if(dp) - value |= B00000001; //Turns on the first binary digit (segment) using an OR bitmask - - //Store the digit - SRData[dispID][digit] = value; - - if(debug) - printSRData(); -} - -void setSegments(int dispID, int digit, byte value) -{ - //Parameter checker - if(dispID < 0 || dispID >= numDevices) - { - Serial.println("dispID OoB!"); - return; - } - - if(digit < 0 || digit > maxDigits) - { - Serial.println("digit OoB!"); - return; - } - - if(value < 0 || value > 255) - { - Serial.println("Invalid byte!"); - return; - } - - //Store the digit - SRData[dispID][digit] = value; - - if(debug) - printSRData(); -} - -void clearDisplay(int dispID) -{ +void clearDisplay(int dispID) { initializeSRData(); refreshDisplay(); } -void refreshDisplay() -{ - //Digit Scanner - for(int digit = 0; digit < maxDigits; digit++) - { - //Display Scanner - digitalWrite(LATCH,LOW); - for(int dispID = numDevices - 1; dispID >= 0; dispID--) - { - //Pre-Digit blanker (shifts out 0s to correct digits before sending segment data to desired digit) - for(int blanks = (maxDigits - 1 - digit); blanks > 0; blanks--) - shiftOut(DOUT,CLK,LSBFIRST,0); - - shiftOut(DOUT,CLK,LSBFIRST,SRData[dispID][digit]); - - //Post-Digit blanker (shifts out 0s to remaining digits) - for(int blanks = digit; blanks > 0; blanks--) - shiftOut(DOUT,CLK,LSBFIRST,0); +void refreshDisplay() { + + for(int fet=0; fet