Inputs

Hello,
I have hooked up my arduino to a 7 segment display. Currently the code is as follows

byte seven_seg_digits[10][7] = { { 0,0,0,0,0,1,0 },  // = 0
                                                           { 1,0,0,1,1,1,1 },  // = 1
                                                           { 0,0,1,0,0,0,1 },  // = 2
                                                           { 0,0,0,0,1,0,1 },  // = 3
                                                           { 1,0,0,1,1,0,0 },  // = 4
                                                           { 0,1,0,0,1,0,0 },  // = 5
                                                           { 0,1,0,0,0,0,0 },  // = 6
                                                           { 0,0,0,1,1,1,1 },  // = 7
                                                           { 0,0,0,0,0,0,0 },  // = 8
                                                           { 0,0,0,1,1,0,0 }   // = 9
                                                           };

void setup() {                
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
    writeDot(0);  // start with the "ian" off
}


void writeDot(byte dot) {
}
  void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte segCount = 0; segCount < 10; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
//Ian officailly did something
  }
  }

void loop() {
{  int Count=5;
  if(digitalRead(12) == HIGH && digitalRead(11) == LOW);
   sevenSegWrite(Count+1); 
   delay(1000);
 }
   int Count=5;
  if(digitalRead(11) == HIGH && digitalRead(12) == LOW);
   sevenSegWrite(Count-1); 
   delay(1000);
}


    
    //done

This program should if the switch is positive count upwards and if it is negative downwards

Here is a fritzing picture

THANKS
MICHAEL

Is there a question associated with this post?

Was there a question?

Why is count reinitialised every loop?

I would think that count should not be in the loop because every time it goes thru the loop it sets count back to 5!
Maybe something like this

byte seven_seg_digits[10][7] = { { 0,0,0,0,0,1,0 },  // = 0
                                                           { 1,0,0,1,1,1,1 },  // = 1
                                                           { 0,0,1,0,0,0,1 },  // = 2
                                                           { 0,0,0,0,1,0,1 },  // = 3
                                                           { 1,0,0,1,1,0,0 },  // = 4
                                                           { 0,1,0,0,1,0,0 },  // = 5
                                                           { 0,1,0,0,0,0,0 },  // = 6
                                                           { 0,0,0,1,1,1,1 },  // = 7
                                                           { 0,0,0,0,0,0,0 },  // = 8
                                                           { 0,0,0,1,1,0,0 }   // = 9
                                                           };

void setup() {                
 int Count=5;

  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
    writeDot(0);  // start with the "ian" off
}


void writeDot(byte dot) {
}
  void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte segCount = 0; segCount < 10; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
//Ian officailly did something
  }
  }

void loop() {
{
  if(digitalRead(12) == HIGH && digitalRead(11) == LOW);
   sevenSegWrite(Count+1); 
   delay(1000);
 }
  if(digitalRead(11) == HIGH && digitalRead(12) == LOW);
   sevenSegWrite(Count-1); 
   delay(1000);
}

count declared in setup is not in scope in loop

Even if it were in scope by declaring it as a global variable it is never updated in loop() anyway so the range of numbers displayed will be severely limited.

You would have to add or take away from count each time you go thru the loop

void loop() {
{
  if(digitalRead(12) == HIGH && digitalRead(11) == LOW);
    Count++;
   sevenSegWrite(Count); 
   delay(1000);
 }
  if(digitalRead(11) == HIGH && digitalRead(12) == LOW);
Count--;
   sevenSegWrite(Count); 
   delay(1000);
}

Then if count is over or under a set number set it back to 0 or whatever

if (Count > 1024){
Count =0;
}
if (Count<0){
Count=1024;
}

Here is what I think would work!

byte seven_seg_digits[10][7] = { { 0,0,0,0,0,1,0 },  // = 0
                                                           { 1,0,0,1,1,1,1 },  // = 1
                                                           { 0,0,1,0,0,0,1 },  // = 2
                                                           { 0,0,0,0,1,0,1 },  // = 3
                                                           { 1,0,0,1,1,0,0 },  // = 4
                                                           { 0,1,0,0,1,0,0 },  // = 5
                                                           { 0,1,0,0,0,0,0 },  // = 6
                                                           { 0,0,0,1,1,1,1 },  // = 7
                                                           { 0,0,0,0,0,0,0 },  // = 8
                                                           { 0,0,0,1,1,0,0 }   // = 9
                                                           };

int Count=5;

void setup() {
  // put your setup code here, to run once:
   pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
    writeDot(0);  // start with the "ian" off
}

void writeDot(byte dot) {
}
  void sevenSegWrite(byte digit) {
  byte pin = 2;
  for (byte segCount = 0; segCount < 10; ++segCount) {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
//Ian officailly did something
  }
  }

void loop() {
   if(digitalRead(12) == HIGH && digitalRead(11) == LOW);
   {
    Count++;
    sevenSegWrite(Count); 
    delay(1000);
   }
   if(digitalRead(11) == HIGH && digitalRead(12) == LOW);
   {
   Count--;
   sevenSegWrite(Count); 
   delay(1000);
   }
   if (Count > 9){
   Count =0;
   }
   if (Count<0){
   Count=9;
   }
}
if(digitalRead(12) == HIGH && digitalRead(11) == LOW);

No, that isn't going to work.

sorry about the mess up the question was "Am i using inputs correctly?"
Here is my current changed code:

byte seven_seg_digits[10][7] = { { 0,0,0,0,0,1,0 },  // = 0
                                                           { 1,0,0,1,1,1,1 },  // = 1
                                                           { 0,0,1,0,0,0,1 },  // = 2
                                                           { 0,0,0,0,1,0,1 },  // = 3
                                                           { 1,0,0,1,1,0,0 },  // = 4
                                                           { 0,1,0,0,1,0,0 },  // = 5
                                                           { 0,1,0,0,0,0,0 },  // = 6
                                                           { 0,0,0,1,1,1,1 },  // = 7
                                                           { 0,0,0,0,0,0,0 },  // = 8
                                                           { 0,0,0,1,1,0,0 }   // = 9
                                                           };
int count=0;
int led = 13;
void setup() 
{                
  pinMode(2, OUTPUT);   
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(11, INPUT);
  pinMode(12, INPUT);
  pinMode(led, OUTPUT);
  count = 2;
}

void sevenSegWrite(byte digit) 
{
  byte pin = 2;
  for (byte segCount = 0; segCount < 7; ++segCount) 
  {
    digitalWrite(pin, seven_seg_digits[digit][segCount]);
    ++pin;
  }
}
void flashDot()
{
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
}

void loop() 
{
  if (count < 9 && digitalRead(12) == HIGH)
  {
     sevenSegWrite(count++); 
  }
  else if(count > 0 && digitalRead(11) == HIGH)
  {
     sevenSegWrite(count--); 
  }
  else
  {
    flashDot();
  }
  delay(1000);
}

Thanks
MICHAEL

Am i using inputs correctly?

No idea because you have not said how you have wired them up.
Pull up resistor?
Pull down resistor?
No resistor?

No resistor

Michael

So how can you be sure whether the inputs are HIGH or LOW when the input pins are at a floating voltage most of the time ?

Your code looks like pins 11 and 12 are pulled HIGH then the buttons are pressed or the switches are operated but what voltage are they at when not pressed/operated ?

michael-schmid:
No resistor

Then no you are not using them right.
Read this:-
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html