Let's Make Robots!

Problem with robot program select menu

I have a problem with programming a menu for selecting my programs for my robot.

The program has to show 9 numbers from 1 to 9 on a 7-segment display, representing a program(avoidance, linefollowing,....)

With 2 switches you go up or down a number and you comfirm with the 3the button(selecting the program you want). The 3 buttons are 1 input that gives a different value depending which button is pressed.

 

Now, the program I have written( in C) only gives a 9 when I start up the robot(not 1 of the buttons has effect on the numer appearing). I was wondering if you guys would help me find the solution to my robots problem.

Thanks, Danny

 

Here is my code.

void ShowNumber(void)
    {
    if(Number=1)
    {
        NumberOne();// Is showed on the display
    }
    if(Number=2)
    {
        NumberTwo();// Is showed on the display
    }
    if(Number=3)
    {
        NumberThree();// Is showed on the display
    }
    if(Number=4)
    {
        NumberFour();// Is showed on the display
    }
    if(Number=5)
    {
        NumberFive();// Is showed on the display
    }
    if(Number=6)
    {    
        NumberSix();// Is showed on the display
    }
    if(Number=7)
    {    
        NumberSeven();// Is showed on the display
    }
    if(Number=8)
    {    
        NumberEight();// Is showed on the display
    }
    if(Number=9)
    {
        NumberNine();// Is showed on the display
    }
    
    }    

void Choseprogram(void)
    {
    keuzesensor=a2dConvert8bit(3);
    while(keuzesensor < 150 || keuzesensor > 110)// If the confirmbutton isn't pushed
    {
    keuzesensor=a2dConvert8bit(3);
    
    if(keuzesensor > 170 && keuzesensor < 210)//1ste button
    {
    Number+=1;
    delay_cycles(10500);
    }
    
    if(keuzesensor > 60 && keuzesensor < 90)//second button
    {
    Number-=1;
    delay_cycles(10500);
    }
    
    if(Number> 9)
    {
    Number=9;
    }
    
    if(Number< 1)
    {
    Number=1;
    }
    
    ShowNumber();
    delay_cycles(1000);
    }

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

This chip turn 4 outputs(BCD) from my microcontroller in outputs for the 7-segment display.

 

Danny

hm my line following code for 5 sensors eats up 4kb of flash of 8kb... :| wonder how will you make those 9 menus even with LCD library too

I don't use an lcd, just 1 7-segment led display.

 

Danny

thats seven ports no matter how I calculate... or do you use register shifter via I2C?

This chip turn 4 outputs(BCD) from my microcontroller in outputs for the 7-segment display.

 

Danny

The robot menu works fine now.

Gonna finish all the different programs now(line following, avoidance, wall following,...)

Thanks for all the advice.

 

Danny

== should be used, put a 10nF cap in paralel with the button for debounce and you could simply use a switch - case statement and change the button counter in an interrupt

You might also be better off with a switch case statement

http://www.arduino.cc/en/Reference/SwitchCase

You can also change;

if(Number> 9)
    {
    Number=9;
    }

to

if (Number > 9) Number = 9;

for a more compact syntax.

Did you do debounce of button?

yeah that what the delay is for.