Go Down

Topic: 16-seg 5 Way Switch (Read 706 times) previous topic - next topic

Msquare

Nov 21, 2011, 05:17 pm Last Edit: Nov 21, 2011, 05:21 pm by Msquare Reason: 1
This post is in reply to a question on youtube.
http://www.youtube.com/watch?v=oVv_nandsKk
I have answered this question by refering to this thread - YouTube Comments not suitable for long answers

Question:
Quote
Hi!
Being a novice, for the displaying part of your test here: is? there anywhere I could read a schematic (limiting resistors and all) on how to hook up this 16seg digit to my arduino? Most greatful...


Answer:
I did it it the "wrong" way, because I was too lazy and it only was for a tiny test. From the Arduino Mega direct to the segments. One resistor in the common ground return. It properly should be one resistor between the arduino pin and the segment pin. (In fact, for the video I removed the resistor so the LEDs were more visible. Bad, bad ...)

Here is the program, the comments explain the wiring, and it also shows the use of arrays.
Code: [Select]
/* Driving the Alpha 16seg display from the 5way switch
 Requires the Mega (number of pins)

    Pinout          Arduino pins
  --2--  -19--     -30-  -35-
 |  \   |  /  |  | \   |  /  |         +-v-+
 4  3  20 18 17  34 32 31 33 37   14 U |   | R 18
 |   \  | /   |  |   \ | /   |    15 E | * | Com GND
  --6--  --15-     -36-  -39-     16 L |   | D 17
 |   /  | \   |  |   / | \   |         +---+
 7  8  10 13 14  38 42 44 43 41
 | /    |   \ |  | /   |  \  |
  --9--  --12-     -40-  -45-
    5, 15 +ve

Mode 0 : Just flash segments on Alpha display
        (Serial "echo" of 5Way)
Mode 1 : "Echo" joy stick position with spokes in middle. E lights edge, too
Mode 2 : Show Alphabet, L/R scroll through, U/D Digit/Alpha (Not Yet Written)
*/
#define MODE1

const byte AP[] = { // arranged: outer ring, inner spokes, clockwise
 35, 37, 41, 45, 40, 38, 34, 30,
 31, 33, 39, 43, 44, 42, 36, 32  } ;
const byte WP[] = { // arranged U-R-D-L-E (clockwise)
 14, 18, 17, 16, 15 } ;
 
const byte ZP[] = { // Maps calculated switch value to a segment entry (inner spokes)
 0, 8, 10, 9, 12, 0, 11, 0, 14, 15, 0, 0, 13 } ;
const byte QP[] = { // Maps calculated switch value to two segment entries (outer ring)
 7,0, 1,2, 0,1, 3,4, 0,0, 2,3, 0,0, 5,6, 6,7, 0,0, 0,0, 4,5  } ;

int Q = 0 ;
void setup() {
 pinMode(13,OUTPUT);
 // Setup for driving 16 output ports
 for (int p=0; p<16; p++) {
   pinMode(AP[p],OUTPUT) ;
   digitalWrite(AP[p],HIGH) ; // display is active LOW (common Anode)
 }
 // Setup for driving 5 input ports
 for (int p=0; p<5; p++)  {
   pinMode(WP[p],INPUT) ;
   digitalWrite(WP[p],HIGH) ;  // Pullup resistor
 }
//  Serial.begin(9600) ;
}

void loop() {
#ifdef MODE0
 for (int p=0; p<16; p++) {
   // clockwise wheel
   digitalWrite(AP[p],LOW) ;
   delay(100);
   digitalWrite(AP[p],HIGH) ;
   digitalWrite(13,(p%2)?LOW:HIGH) ; // blink
 }
#endif
#ifdef MODE1
 byte Z = 0 ;
 for (int q=0; q<16; q++) digitalWrite(AP[q],HIGH) ; // turn everything off
 for (int p=0; p<4; p++)
   if (digitalRead(WP[p])==LOW)  Z += 1<<p ;
//  delay(1000) ; Serial.print(Z,DEC) ; Serial.print(":");Serial.print(ZP[Z],DEC) ; Serial.print(" ");
 if (Z) {
   digitalWrite(AP[ZP[Z]],LOW) ;  
   if (digitalRead(WP[4])==LOW) {
     digitalWrite(AP[QP[(Z-1)*2  ]],LOW) ;
     digitalWrite(AP[QP[(Z-1)*2+1]],LOW) ;
   }
 } else {
   if (digitalRead(WP[4])==LOW)
     for (int q=0; q<8; q++) digitalWrite(AP[q],LOW) ; // outer ring ON
 }
#endif
}



(Edit - changed subject)

Go Up