Show Posts
Pages: 1 ... 10 11 [12] 13 14
166  Using Arduino / Programming Questions / a common cathode seven segment display library on: December 30, 2012, 07:29:17 am
Hi guys! I have made an improvement to the seven segment library I made a while ago.
The library works for common cathode ssds. You can copy the below code in a new tab for your sketch:
Code:
#include<Arduino.h>
int a;
int b;
int c;
int d;
int e;
int f;
int g;
void sevensegpins(int z, int y, int x, int w, int v, int u, int t){
  a=z;
  b=y;
  c=x;
  d=w;
  e=v;
  f=u;
  g=t;
  pinMode(a, OUTPUT);
  pinMode(b, OUTPUT);
  pinMode(c, OUTPUT);
  pinMode(d, OUTPUT);
  pinMode(e, OUTPUT);
  pinMode(f, OUTPUT);
  pinMode(g, OUTPUT);
}
void clearall(){
  digitalWrite(a, LOW);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, LOW);
  digitalWrite(f, LOW);
  digitalWrite(g, LOW);
}
void zero(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
}
void one(){
  clearall();
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
}
void two(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(d, HIGH);
}
void three(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
}
void four(){
  clearall();
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
}
void five(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
}
void six(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
}
void seven(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
}
void eight(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
void nine(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
}
/*void a(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
void b(){
  clearall();
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(g, HIGH);
}
void d(){
  clearall();
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
void f(){  
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(g, HIGH);
  }
void h(){
  clearall();
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
}
void l(){
  clearall();
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
}
void p(){
  clearall();
  digitalWrite(a, HIGH);
  digitalWrite(b, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
}
void q(){
  nine()
}
void s(){
  five();
}
void u(){
  clearall();
  digitalWrite(b, HIGH);
  digitalWrite(c, HIGH);
  digitalWrite(d, HIGH);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
}*/
void sevenseg(int val){
  if(val==0){
    zero();
  }
  if(val==1){
    one();
  }
  if(val==2){
    two();
  }
  if(val==3){
    three();
  }
  if(val==4){
    four();
  }
  if(val==5){
    five();
  }
  if(val==6){
    six();
  }
  if(val==7){
    seven();
  }
  if(val==8){
    eight();
  }
  if(val==9){
    nine();
  }
}

The
Code:
sevensegpins()
function will do the pinModes for you. Put the pins the segments A to G are connected in the brackets in order.
The
Code:
sevenseg
function displays. Example:
Code:
sevenseg(5);
This is a sample:
Code:
#include"sevenseg.h" //include the library
int val=0; //integer to store analog readings
void setup(){
  sevensegpins(13, 12, 11, 10, 9, 8, 7); //initialize the segment pins
}
void loop(){
  val=(analogRead(0));
  val=map(val, 0, 1023, 0, 9); //remap the sensor readings to 0-9
  sevenseg(val); //display the sensor readings on seven segment display
}
Thank you for looking at this! Please comment!
167  Using Arduino / LEDs and Multiplexing / Re: Dot Matrix on: December 01, 2012, 02:47:29 am
Yes, I will connect all the pins to the Arduino. I have a regular 8x8 matrix and I have figured out the pin formation.
Thanks!
Habib
168  Using Arduino / LEDs and Multiplexing / Dot Matrix on: November 30, 2012, 08:23:00 pm
Hi dear friends! I am just beginning to understand the led dot matrix. Does anybody know what code I should use to drive the matrix directly? Or is there a library? I use an 8x8 matrix.
Thanks a lot!
Habib
169  Using Arduino / Programming Questions / Re: A compiling error with LCD code on: October 26, 2012, 09:03:35 am
Thanks a lot! That was a silly mistake!
170  Using Arduino / Programming Questions / Re: A compiling error with LCD code on: October 26, 2012, 08:29:20 am
Oh yeah here is some more code:
Code:
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 2, 3, 4, 5);
/*some code skipped*/
void setup(){
    lcd.begin(16,2);
    cd.print("welcome");
}
171  Using Arduino / Programming Questions / A compiling error with LCD code on: October 26, 2012, 08:00:14 am
Hi everybody! I am using a 16x2 lcd screen for a project but some of the code isn't working.
Code:
LiquidCrystal lcd(12, 11, 2, 3, 4, 5);
This is the error message:
Code:
the_machine:2: error: 'LiquidCrystal' does not name a type
the_machine.cpp: In function 'void setup()':
the_machine:45: error: 'lcd' was not declared in this scope
the_machine.cpp: In function 'void loop()':
the_machine:72: error: 'lcd' was not declared in this scope
the_machine:90: error: expected `)' before 'setlvl'
the_machine:95: error: expected `)' before 'setlvl'
the_machine:100: error: expected `)' before 'settemp'
the_machine:105: error: expected `)' before 'settemp'
I wonder if anybody can help me with this. Thanks!
172  Using Arduino / Programming Questions / Re: Question about a function on: October 13, 2012, 05:53:31 am
Oh sorry in the IDE "display" was in orange so I thought it was a function.
173  Using Arduino / Programming Questions / Re: Question about a function on: October 13, 2012, 01:40:19 am
It's some code for a seven segment display(that's right Mr. John), here's some more code.
Code:
display[] = {
B00111111, // 0
B00000110, // 1
B01011011, // 2
B01001111, // 3
B01100110, // 4
B01101101, // 5
B01111011, // 6
B00000111, // 7
B01111111, // 8
B01101111, // 9
}
// write the digits, assume PORTD with bit0 = asegment, 1=b,2=c,3=d,4=e,5-f,6=g, 7=decimal point it used
//    a
// f    b
//    g
// e   c
//    d
// clear the bits
PORTD = PORTD & 0x00
// now set the font
PORTD = display[x]; // x = 0 to 9, or bigger if define some other characters: A,b,C,d,E,F,H,L,P,U, -,_,
174  Using Arduino / Programming Questions / Re: Question about a function on: October 12, 2012, 08:31:56 pm
P.S. here's some more code with the "display function:
Code:
PORTD = PORTD & 0x00
PORTD = display[x];
175  Using Arduino / Programming Questions / Question about a function on: October 12, 2012, 08:02:35 pm
Just wanted to ask what does this do
Code:
display(val);
I tryed looking in the reference tab but couldn't get anything. If anyone can help me I would be very grateful.
176  Using Arduino / LEDs and Multiplexing / Re: A simple single digit seven segment display on: October 12, 2012, 10:24:35 am
Thank you very much!. I may have a little trouble with it but I'll figure it out. Thanks again! smiley smiley smiley
177  Using Arduino / LEDs and Multiplexing / Re: A simple single digit seven segment display on: October 12, 2012, 10:22:13 am
Thank you very much. I might have a little trouble figuring it out, but I'll try. Thanks again
178  Using Arduino / LEDs and Multiplexing / Re: A simple single digit seven segment display on: October 12, 2012, 07:56:24 am
I will give you a skeleton:

0) define a bunch of macros to turn on / off segments / digits. Those macros are Common Cathod or Common Anode aware.
1) use a routine to initialize all pins.
2) write a code that upon each call, display one digit from a buffer, and rolls over to the next.
3) set up a timer, pointer a function pointer to the routine in 2) above.
4) in the timer isr, execute the function pointer (now pointing to the routine in 2)).

Once that is up, the entire display function is transparent to the user. All the user code needs to do is to fill the buffer as needed and the display routine will update the buffer automagically.

Thank you so much @dhenry! Thank you for the support! I will go by what you said!
179  Using Arduino / LEDs and Multiplexing / Re: A simple single digit seven segment display on: October 12, 2012, 07:43:44 am
Thanks so much for the feedback dear friends! I shall modify the library.
180  Using Arduino / LEDs and Multiplexing / Re: A simple single digit seven segment display on: October 12, 2012, 06:20:36 am
That's a great idea! Thanks a lot!
Pages: 1 ... 10 11 [12] 13 14