Go Down

Topic: My first solo atempt (Read 818 times) previous topic - next topic

todda

Hi All,
I decided to try my hand at my first solo project after going through a chunk of the tutorials.
I also decided to share it with you all, dont laugh I know its crap but its my first go.
Plus if anyone has any tips, tricks, tweaks or advice id be happy to listen.



Code: [Select]
#include <ks0108.h>
#include <Arial14.h>
#include "SystemFont5x7.h"
#include "DICE/ONE.h"
#include "DICE/TWO.h"
#include "DICE/THREE.h"
#include "DICE/FOUR.h"
#include "DICE/FIVE.h"
#include "DICE/SIX.h"
int number;
int button;
void setup(){
  pinMode(42, INPUT);
  GLCD.Init(NON_INVERTED);
  GLCD.SelectFont(System5x7);
  GLCD.ClearScreen();
  GLCD.CursorTo(0, 2);
  GLCD.Puts("Press the button");
  GLCD.CursorTo(0, 4);
  GLCD.Puts("to roll the dice.");
}


void loop(){
  number = random(1, 7);
  button = digitalRead(42);
  if (button == 1){
    GLCD.ClearScreen();
    if (number == 1)
    {
       GLCD.DrawBitmap(ONE, 0,0, BLACK);
    }
    if (number == 2)
    {
      GLCD.DrawBitmap(TWO, 0,0, BLACK);
    }
    if (number == 3)
    {
      GLCD.DrawBitmap(THREE, 0,0, BLACK);
    }
    if (number == 4)
    {
      GLCD.DrawBitmap(FOUR, 0,0, BLACK);
    }
    if (number == 5)
    {
      GLCD.DrawBitmap(FIVE, 0,0, BLACK);
    }
    if (number == 6)
    {
      GLCD.DrawBitmap(SIX, 0,0, BLACK);
    }
    delay(5000);
    GLCD.ClearScreen();
    GLCD.CursorTo(0, 1);
    GLCD.Puts("Press the button");
    GLCD.CursorTo(0, 3);
    GLCD.Puts("to roll the dice.");
  }
}

johnwasser

Your pull-down resistor is hooked to the wrong side of the button.  It should connect the input pin to ground.  The button connects the pin to +5.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy