Show Posts
Pages: 1 2 [3] 4
31  Using Arduino / Project Guidance / Re: just a thank you.. on: January 14, 2013, 03:17:06 am
wow, thanks for the mention!
and you are both more than welcome smiley
I am glad my very frustrating weekend project was able to help someone get results smiley-razz
I had to bail on my original 7seg idea, and opted for an LCD display instead (made the headache go away)

Now I have all kinds of ideas running though my head, this LCD screen has really opened up some options!

I can't wait until my daughters are old enough to start teaching this stuff too.  They could easily make their own toys, and have fun in the process!
Great parent-child project, and I hope you guys are having fun!
32  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 14, 2013, 03:06:24 am
Soooo, here we go, totally revised v4.o

I finally threw in the towel on making a dual 7seg display, even with some code I simply copied and pasted, it wasn't quite working right.  (the code I copied was for a 4 digit display, while I only had two digits, had to mod it a little, and lost something in the translation...)  it would not scroll the message properly, so I got pretty frustrated after a whole weekend spent on it, and went to radio shack and picked up a simple LCD display...

I really like this option for my project, and I think it works better anyway.  Now I can always display on the screen which dice mode you are in, and I am now starting to think of ways to add more dice to the mix.  that way you can roll multiple dice at the same time.  probably going to use a toggle switch and some basic digitalRead arguments to tell the arduino to display 2 or maybe even 3 random results of the current dice mode.  Really increase the functionality of this thing.

So far, everything is working nearly perfect.  Only glitch is, when I have cycled through all the dice modes, my default D2 mode (coin flip) is called D1 instead of D2.  When it first comes on, it shows D2, then D4, D6, D8, D10, D12 and D20 as you cycle through the modes.  One more button push should cycle back to D2, but instead reads D1.

here is my code...

#include <LiquidCrystal.h>

LiquidCrystal lcd(2,3,4,5,6,7);

const int mButton = 9;
int mode = 0;
int oldMode = 0;
const int Tilt = 8;
int val = 0;
int oldVal = 0;
int state = 0;

int dValue[] =

long result;

void setup()
  pinMode(Tilt, INPUT);
  pinMode(mButton, INPUT);
  lcd.print("DigiDice - D");

void loop()
    mode = digitalRead(mButton);
    if ((mode == HIGH) && (oldMode == LOW))
        lcd.print("DigiDice - D");
    if (state > 6)
      state = 0;
    oldMode = mode;
  val = digitalRead(Tilt);
  if ((val == HIGH) && (oldVal == LOW))
    result = random(1, dValue[state] + 1);
    lcd.setCursor(0, 1);
    lcd.print("Result = ");
    lcd.print("       ");
  } else
    lcd.print("Give Me A Shake");

sorry for the lack of comments, I honestly just threw this together on the fly, and it worked nearly out of the box.  I haven't taken the time to comment it yet, but will before I am all done.
pretty basic code, and the LiquidCrystal library is great!  Made this a snap.
if anyone could let me know why my dice mode is displaying wrong (I still get the correct expected results, no false numbers outside the dice range) and maybe point me to a fix, I would greatly appreciate it!

This has been a very twisty, educational project for me, and I cannot express how much I have appreciated everyone who took the time to try and walk me through this.
33  Using Arduino / LEDs and Multiplexing / Re: 0.56" RED 7 SEGMENT LED DISPLAY COMMON ANODE 41056 - (SOLVED) on: January 13, 2013, 11:18:23 am
glad that worked!

I am very very new at this, and have been struggling with my own project today...
it is nice to be able to help someone else for a change smiley-razz
34  Using Arduino / LEDs and Multiplexing / Re: 0.56" RED 7 SEGMENT LED DISPLAY COMMON ANODE 41056 - help please on: January 13, 2013, 11:02:54 am
I used that same tutorial a few days ago, good starting place in my opinion.

The code written in that example is for a common cathode 7 segment display.

since yours is a common anode, you need to reverse the code a little.

basically, in the array used to display the digits, you need to switch the ones to zeros and the zeros to ones.
once you do that, it should work, provided this is the issue you are having.

as to your second question, yes, you can test the pins that way.
just write arduino pin 8 LOW and connect the common anode (either display pin 3 or 8 ) to a resistor and the 5v on your arduino.  then hook arduino pin 8 to each of the cathode pins (display pins 1, 2, 4, 5, 6, 7, 9 and 10) and see which one light up.  pin 7 on the display should be the top middle segment
35  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 13, 2013, 10:26:22 am
At this point, I am absolutely convinced I am over-thinking this issue,

More importantly, you are under-doing it: sit in front of your arduino / ide and start coding one step at a time.

Thanks for the reply!
actually, I have tried writing this up several ways, but haven't even been able to get both displays to work yet.
I have had all kinds of odd results (the right character showing up on the wrong display, and only half brightness, both characters showing on one display one after the other, things like that, but most of the time, I get no result.)

I have been scribbling code on paper all day trying to get this straight in my head.  Not sure why I am having so much trouble honestly.  everything else I have tried on the arduino has ended up being pretty cut and dry, and worked.  At most I have maybe had to scratch my head for an hour or so, until I stumbled on a sample code that I could use correctly to do the job.
I have even had this project working perfectly with a single seven segment display, but wanted to expand it as a challenge to myself, and to learn about multiplexing.
I figured all I would have to do is merge my working code with some example multiplexing code and viola, working digital dice that could be used in a multitude of dice games.
as a matter of fact, once I had this working with my basic setup, I am even looking to add a few more modes, that would allow each display to show results for a single die, allowing for a person to roll two dice at once, and skip having to see one result for three seconds, then roll again to get a second result.

For the overall project I have a long way to go, but I am trying to teach myself the code step by step and increase the complexity as I get one part working.

I really appreciate the advice and patients I am getting with this.  I have only been working with electronics for less than two years, and only learned how to use ICs about 6 months ago (555 timer aside, it's hard to learn electronics without running into some good 555 timer projects)
I have had my Arduino for maybe two weeks, and have learned more on how to use it in the last two weeks than I have basic electronics in the last two years.
Much that is discussed on forums such as this one are a bit over my head with the abbreviations and terms I am not familiar with, and I usually just look things up as I run into new information.  Usually this process works well for me, but today has been one of those "can't quick wrap my head around it" kind of days...

I am sure I will get it, it will just take some time, and a little tweaking of my current learning curve smiley-razz
36  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 13, 2013, 09:46:09 am
ok, couple of quick (hopefully) easy questions.

should I write the array to define the answer as 0-9 or as 0-20.
My highest dice value will be 20, but that can be broken down into 2 and 0 on the display.
I am not sure if I need to write a byte value for 10-20, and if so, how would I do that.

It seems to me it would be easier to write the array 0-9 and call up the proper byte for each digit on each display.

At this point, I am absolutely convinced I am over-thinking this issue, but I have looked at so many different ways of handling a two digit 7 segment display, I think I am getting lost in the options.

second, what exactly is a timing isr?
I know that is probably a dumb question, but it is a term I haven't run into yet, so I am just trying to make sure I look up the right thing smiley

37  Using Arduino / LEDs and Multiplexing / Re: Digital Dice project on: January 13, 2013, 04:34:42 am
Thanks for the response and the link to the list of libraries!
Looks like you have some useful ones in there smiley
couple of questions,
do you have any example code you could show me for handling the library?
is there a way to use the library if I don't have the HC595 IC?  (I don't have any 72 series ICs, only some 74 series and a 4026, which I honestly haven't figured out how to combine, which is why I am trying to do this without the ICs at the moment.)
if I am understanding this correctly, your code uses the HC595 shift register to handle the output.  The ICs I have are all TTL, and I don't know if they will do the same thing.  I am nearly as new to electronics in general as I am to Arduino. 
I can take a schematic and make it a working circuit, but I don't always know what is happening within the circuit.

Sorry for my lack of experience, I am learning as fast as I can, but the amount of available information can be an overload at times.  Especially when you are trying to make a simple project like this.  Many options, but none seem to fit the exact project design I have come up with.
38  Using Arduino / LEDs and Multiplexing / Digital Dice project on: January 12, 2013, 06:59:18 pm
Hello all  smiley
Having some trouble coming up with a clear path to my current project, which is a set of digital dice.
First I will give a quick overview of my project, then I will get to the problem I am having.

I am trying to build these dice with multiple modes.  They are based on a full set of D&D dice, so the dice values I want to use are 2, 4, 6, 8, 10, 12, and 20.  I am using a push button to switch dice modes, then a tilt switch to "roll" the dice.

I have already made this work fairly easily with a single 7 segment display, using the dot segment to indicate a double digit number.  Now I am trying to use two 7 segment displays to show the results.
I am trying to do this without using any off-arduino ICs.  I am using two common cathode 7 seg displays.  I have the segments tied together and a couple of 2n2222a transistors on the common cathodes to handle the switching, giving a multiplex effect.

I would post my code, but nothing I have wrote has even come close to working.  I have tried modifying some examples I have found to suit my project, but haven't had any luck there either.  All of the samples I can find either use external ICs or they scroll a prepackaged message, rather than simply displaying the result of a random function. 
I know how to get the random function to work, and how to tell the arduino where to set the result limits based on which dice mode you are in.
What I do not know is how to take that result, break it down into two separate digits, and display one number on each 7 seg.

If anyone has any suggestions, or can point me to some sample code that could be modified to get this working, I would greatly appreciate it!

Thanks in advance for any suggestions
39  Using Arduino / Project Guidance / Re: (not a ) switch case question (anymore...) on: January 12, 2013, 02:30:07 pm
Ok, I seem to have hit a wall today...

I have re-designed my digital dice project.
I am now trying to use two 7 segment displays to show the dice roll results.
I am trying to multiplex them without external ICs.
they are both common cathode displays, and I have the segments for both wired together, and the cathodes wired through 2n2222a transistors to perform the multiplexing.
I have the segments mapped out correctly, and have already tested that.
I am having trouble getting the results to display.
basically, I don't have a clue how to take the double digit result of the random function, and correctly display them on the two displays.

Looking for any guidance or links that would show me how to do this.  There are loads of tutorials and examples of how to use the 7seg, and how to multiplex them, but they all seem to have some pre-packaged message to scroll or display, and not how to display numbers that the arduino comes up with internally.

sorry if my description is unclear, and if anyone has any questions on my project, I am more than happy to answer them.
40  Using Arduino / Project Guidance / Re: switch case question on: January 09, 2013, 01:05:42 pm

I am sure you are correct.
I haven't wrote my own function without working directly from an example before, but I am sure with a little digging, I can figure it out.

I actually have some idea of how I would do that, though it will take some testing to find out.
Thank you for the suggestion!
This is my goal, to figure out how to get my idea working on my own, then get help from others to learn where I can make it better.
many more things that get talked about on this forum are making sense, and I always enjoy the process!
41  Using Arduino / Project Guidance / Re: code suggestions on: January 09, 2013, 12:54:33 pm
Thanks for the info...yes, could you please post the code.

I post this with the caveat that I am very new, and this is litterally the first project I made that wasn't in a book or tutorial.  It also happens to be the last project I did before yesterday smiley-razz
I am not positive that this is the best way to do this, but it does work, and should show the use of the "NewPing" library well enough to give you some idea how to use it...
when you download the library from this link

there are some great examples that were a great help to me in writing this code...

//This sketch uses a PING))) ultrasonic sensor to sense distance in cm
//and use that data to activate a 6 LED bar graph, with a piezzo buzzer
//to sound out warnings at close intervals.

#include <NewPing.h>  //includes the NewPing library
#define TRIGGER_PIN 8  //defines the trigger pin as 8
#define ECHO_PIN 8     //also defines the echo pin as 8
#define MAX_DISTANCE 400  //sets the maximum distance the sketch will use
#define ITERATIONS 10   //defines how many times you want the sonar to ping

//defines for the library that "sonar" uses the trigger pin, echo pin and
//and max distance as definitions

int BUZZ = 10; //sets the buzzer to pin 10

const int minDist = 0;    //defines constant minDist as 0cm
const int maxDist = 161;  //defines constant maxDist as 161cm
int BUZZstate = LOW;  //defines variable BUZZstate as LOW
long prevBUZZ = 0;  //defines long "prevBUZZ" and stores it
long interval = 500;  //defines long "interval" and sets it to 500

const int ledCount = 6;  //defines constant "ledCount" and sets it to 6

int ledPins[] =  //defines the variable ledPins as an array ranging from 2-7
  2, 3, 4, 5, 6, 7

void setup()
  pinMode(BUZZ, OUTPUT);  //sets the BUZZ pin (10) as an output
  //for loop to increment thisLED up by one and to ser thisLED to the array
  //ledPins and set those pins as OUTPUT
  for (int thisLED = 0; thisLED < ledCount; thisLED++)
    pinMode(ledPins[thisLED], OUTPUT);
  Serial.begin(115200);  //begin Serial communication at 115,200 baud

void loop()
  delay(30);  //wait 30mS
  //defines "uS" as an unsigned integer sets it to "sonar" then take 10 ITERATIONS
  //and find the median of them.
  unsigned int uS = sonar.ping_median(ITERATIONS);
  //uses Serial data to print the result in cm (Ping: XXcm) to the monitor
  Serial.print("Ping: ");
  Serial.print(uS / US_ROUNDTRIP_CM);
  //defines the variable "ledLevel" and maps it to (distance in cm) from zero
  //up to 161cm, and sets the ledCount down to 0 to that map, to turn on more LEDs
  //the closer you get and to turn them off further away
  int ledLevel = map(uS / US_ROUNDTRIP_CM, 0, 161, ledCount, 0);
  //for loop to incement "thisLED" up by one and turn them on or off by the ledCOUNT
  for (int thisLED = 0; thisLED < ledCount; thisLED++)
    //if statement for turning the LEDs on or off in the for loop
    if (thisLED < ledLevel)
      digitalWrite(ledPins[thisLED], HIGH);  //turns LED on
    } else {
      digitalWrite(ledPins[thisLED], LOW);  //turns LED off
      //uses a switch case to control when the peizzo buzzes based on the ledCount
        case 1:  //LED 1, no sound
        digitalWrite(BUZZ, LOW);
        case 2:  //LED 2 no sound
        digitalWrite(BUZZ, LOW);
        case 3:  //LED 3 no sound
        digitalWrite(BUZZ, LOW);
        case 4:  //LED 4 no sound
        digitalWrite(BUZZ, LOW);
        case 5:  //LED 5 will cause the piezzo to signal a series of regular short beeps
          unsigned long BUZZmillis = millis();
          if(BUZZmillis - prevBUZZ > interval)
            prevBUZZ = BUZZmillis;
            if (BUZZstate == LOW)
            BUZZstate = HIGH;
            BUZZstate = LOW;
            digitalWrite(BUZZ, BUZZstate);
        case 6:  //LED 6 will cause the piezzo to make a continuous tone when the distance is shortest
        digitalWrite(BUZZ, HIGH);

Hope that helps, building a robot is one of the next things I want to tackle.
Good Luck!
42  Using Arduino / Project Guidance / Re: switch case question on: January 09, 2013, 12:38:53 pm
you just solved my last problem!
I was trying to work out a way to keep track of the dice mode, but I only have two pins left.  using a push button is perfect, and comes with more options than a few regular LEDs to indicate level or something else that I might have thought up.
Great idea

Thanks for the suggestion!
much more simple than what I was thinking!
43  Using Arduino / Project Guidance / Re: code suggestions on: January 09, 2013, 09:48:43 am
I had made a distance sensor using the PING and was having the same issues, random erratic returns from the PING
How I fixed it was by using the library you can download called NewPing.
There are options in that library to take many readings per second from the PING and average them.  It stabilized the data I got from the PING sensor and stopped the erratic readings completely.

There are good examples for the library to write the code from, and if it would help, I can post the code I wrote as an example also smiley
44  Using Arduino / Project Guidance / Re: switch case question on: January 09, 2013, 09:08:45 am
I notice that the definitions of the number representations start at '1'. I guess that this is because none of your dice have a zero on them. smiley Nevertheless, it would make your display code more reusable (and exclude a possible source of off-by-one errors) if you started the numbers from '0'. This would enable you to use the number directly as an index into the array.

actually, I ran into that very problem and this is how I fixed it.  I originally had "0" at the top of the list, but that was displaying the dice result from 0-Xdice mode instead of 1-Xdice mode.  I put "0" at the end, which screwed up my code to display which dice mode you were in, by saying "d1" instead of "d2" or "d9" instead of "d0." (for d10).  To fix that, I used the "sevenSegWrite(dValue[state] - 1)" and everything worked out just right.
I could have just of easily used sevenSegWrite(Result + 1) but I didn't see that at the time.  Once I had it working, I was fairly timid to try and change it again.

Thank you for the suggestion though!
Very much appreciated, and I agree, starting at 0 and adding 1 to the result would have made some other parts of the code easier to write for accessing the array. 
I am just happy to have the thing working at this point.  I feel like I have come a long way in a very short time, though it is clear I have a long way to go to be proficient in the least.
45  Using Arduino / Project Guidance / Re: switch case question on: January 09, 2013, 08:57:48 am
No, "0b" is the C binary constant prefix, just as "0x" is the hex constant prefix, and "0" is the octal constant prefix

0b00000100 = 810 = 0x08 = 010 

lol, what I know about C, or writing code in general, wouldn't even be a decent size drop in the overall bucket...

I very much appreciate you pointing me in the correct direction though, and I am off to do some research and learn a bit more about how and why your suggestion would work.

I did attempt to change my code as suggested, but I must be missing something somewhere.  Now when I shake the breadboard to "roll the dice" I only get the very top-middle segment to light up, so I guess its time to actually go through some C tutorials and learn more about the language so I can use it properly.

Thank you so much for your help and guidance though!
my lack of experience in the subject sort of makes communicating a bit tougher, and you have been very patient to follow along and explain things to me smiley
I do understand the direction you are pointing me in, just not the "how" and "why" of it yet.  I will get there
Pages: 1 2 [3] 4