sapo score project using freetronic DMD

Hey All

I’ve got a little project underway and want to use the DMD to display what I need. I posted this on the freetronics board but this one seems more active.

I am NOT a programmer and I have strung together some code from various examples and then had a friend turn it into something a real programmer might write. But anyways, I have most of my output displaying successfully on an LCD screen but I am finding it difficult to do the same with the DMD, primarily because it doesn’t seem like I can print ints, only char - is this right?

In my game i keep running scores for 2 teams and display them both, along with some other messages that are non essential but intended for fun. I’d really like to get the scores displaying and updating on the DMD without doing complicated coding. Hope you guys can help…thanks in advance!!!

here is a link to my project
https://sites.google.com/site/saposcore/

here is the main code. sorry about the comments, i am trying to teach myself how this stuff work. this currently does not work because it errors due to the variables im trying to display via the dmd display functions.

#include "DigitalInput.h"
#include "ScoreTrigger.h"
#include <LiquidCrystal.h>
#include <SPI.h>        //SPI.h must be included as DMD is written by SPI (the IDE complains otherwise)
#include <DMD.h>        //
#include <TimerOne.h>   //
#include "SystemFont5x7.h"
#include "Arial_black_16.h"
#include "Arial14.h"

DMD dmd(1,1);

int NUM_SCORE_TRIGGERS = 0;          // setting this variable to 0 to start, it will be assigned to a different little later

void ScanDMD()
{ 
  dmd.scanDisplayBySPI();
}

CScoreTrigger ScoreTriggers[] = {    //this is an array of [] (unknown) number of items
  CScoreTrigger(4, 500),             //item #1 in this array 
  CScoreTrigger(3, 1000),            //item #2 in this array 
};

CDigitalInput TurnPin(2);            

LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);  
int Score[2] = {0 , 0};                 
int TurnIndex = 0;                      
int NumPlayers = 2;
boolean goodshot = false;
String whosturn = "Team 1";
String greeting = "Nice Shot! ";
char dmdtest[] = "SAPO!";

void setup() {
  
      NUM_SCORE_TRIGGERS = sizeof(ScoreTriggers)/sizeof(ScoreTriggers[0]);  

                               
   TurnPin.Init();             

   for (int i = 0; i < NUM_SCORE_TRIGGERS; i++)  
   {
      ScoreTriggers[i].Init();              

   }


   Timer1.initialize( 5000 );
   Timer1.attachInterrupt( ScanDMD );   
   dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
   dmd.selectFont(SystemFont5x7);
   dmd.drawString(  1,  1, dmdtest , 5, GRAPHICS_NORMAL );

   

   lcd.begin(16, 2);
   lcd.setCursor(0,0);
   lcd.print("Welcome to Sapo!");
   delay(3000);
   lcd.clear();
   lcd.setCursor(0,0);
   lcd.print(whosturn);
   lcd.setCursor(0,1);
   lcd.print("You're up!");
   delay(2000);


}


//
// Loop
// 

void loop() {
   
   TurnPin.UpdateState();

   for (int i = 0; i < NUM_SCORE_TRIGGERS; i++)
   {
      ScoreTriggers[i].UpdateState();
   }

    // Handle players switch
   if (TurnPin.ChangedState(HIGH))
   {
      
      TurnIndex += 1;
                TurnIndex %= NumPlayers;

      if (TurnIndex == 0)
      {
         whosturn = "Team 1";
      }
      else
      {
         whosturn = "Team 2";
      }

      //what to print for a team change       
      
                dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
                dmd.selectFont(System5x7);
                dmd.drawString(  2,  1, whosturn, 4, GRAPHICS_NORMAL );
                dmd.drawString(  0,  9, "GO!", 6, GRAPHICS_NORMAL );
                
                lcd.clear(); 
      lcd.print("Team Change!");
      lcd.setCursor(0,1);
      lcd.print("Next:  ");
      lcd.print(whosturn); 
      delay(1000);  
   }
   else if(TurnPin.ChangedState(LOW))
   {
      lcd.clear(); 
      lcd.setCursor(0,0);
      lcd.print(whosturn);
      lcd.print(" - GO!        ");
   }

   // Handle score
   for (int i = 0; i < NUM_SCORE_TRIGGERS; i++)
   {
      if (ScoreTriggers[i].ChangedState(HIGH))
      {
            
         /// Add Score
                        int nPointValue =ScoreTriggers[i].GetPointValue();
         Score[TurnIndex] += nPointValue;
     
         //set the greeting to mention points
         goodshot = true;
         greeting = "Yes! ";         
         greeting += nPointValue;
         greeting += "!";

dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
              dmd.selectFont(SystemFont5x7);
              dmd.drawString(  0,  0, greeting, 5, GRAPHICS_NORMAL );
                        
      }
      else if (ScoreTriggers[i].ChangedState(LOW))
                
      {         
              dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
              dmd.selectFont(SystemFont5x7);
              dmd.drawString(  0,  0, whosturn, 5, GRAPHICS_NORMAL );
              dmd.drawString( 0,  9, "GO!", 5, GRAPHICS_NORMAL );

           lcd.setCursor(0,0);
         lcd.print(whosturn);
         lcd.print(" - GO!          ");
      }
   }
   
   //if a shot was made, print the following:
   if (goodshot == true)
   {

      dmd.clearScreen( true );   //true is normal (all pixels off), false is negative (all pixels on)
      dmd.selectFont(SystemFont5x7);
      dmd.drawString(  3,  0, Score[0], 5, GRAPHICS_NORMAL );
      dmd.drawString(  3,  9, Score[1], 5, GRAPHICS_NORMAL );

          //lcd.clear();
          lcd.setCursor(0,0);
          lcd.print(greeting);
          lcd.setCursor(0,1);
          lcd.print("1:");
          lcd.print(Score[0]);
          lcd.print(" ");
          lcd.print("2:");
          lcd.print(Score[1]);
          lcd.print(" ");
          goodshot=false;
          delay(1000);
        }
}

cpohara
 
Posts: 1
Joined: Sat Feb 11, 2012 5:15 am

I've got a little project underway and want to use the DMD

What is a DMD? Got a link?

I am finding it difficult to do the same with the DMD, primarily because it doesn't seem like I can print ints, only char - is this right?

So? Use sprintf() or itoa() to do the conversion.

int NUM_SCORE_TRIGGERS = 0;

By convention, all capital letter names are #define'd into existence, and are, therefore, not writable. There are good reasons not to violate convention, and very few good reasons to do so. In this case, I can't see a good reason.

Hi Paul, thanks for replying.

This is the DMD i was referring to

I'll look into your suggestions and let you know if I have any questions. Not being a programmer, I probably will

Thanks!

I found another one of your posts that explained sprintf well enough for me to use it, and now I've got my scores displaying and updating properly AND allowed me to right justify my scoring which was a nagging problem.

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1282237646

i also used this for tips on updating char arrays so i was able to change some of my strings to char arrays. now i'm only using sprintf to change ints to chars for DMD display.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260748012

so, thanks for the direct and indirect help

That leaves me with 2 questions:

  1. Now i need to hook up 20 switches to the game board which has 10 unique scoring values so i need 10 pins for that and 1 pin for the team change button. That's 11, butI only have 10 available. Can I use pins 0 and 1 for digital input? can i use a 2 way momentary switch on the reset pin (reset or switch teams) ?

  2. I've been searching for a 3x5 font and i've even tried editing existing font .h files with no luck. If anyone knows where i can find existing fonts, I'd appreciate it!

Thanks!!!

In my game i keep running scores for 2 teams and display them both, along with some other messages that are non essential but intended for fun. I'd really like to get the scores displaying and updating on the DMD without doing complicated coding. Hope you guys can help...thanks in advance!!!

here is a link to my project