Doing multiplication in trinary not displaying correctly.


hello everyone.  trying make program multiplies 2 numbers in trinary , displays resulting number on 6 leds.  there 2 input switches: first 1 on pin 2 allows input trinary number want, , second switch moves program along in multiplication process.  here specifics of i'm trying accomplish:

quote
have arduino multiplication in trinary follows:

install 2 buttons.  first button entering numbers above (push button once enter 1, twice enter 2, etc).  second button multiplication , clear.

your arduino should operate procedure:

1.      enter first number on button 1.

2.      press button 2 multiplication symbol.

3.      enter second number on button 1.

4.      arduino should display first number times second number in trinary.

5.      press button 2 clear.

6.      can repeat these steps multiply different 2 numbers without resetting arduino.


i have created code think should work, not doing expect of it.  allows me enter in first number on first switch, , when click second switch allowed me input second number second switch.  when hit second switch again, nothing happens, , if hit again program restarts.  doing wrong, since looks should work fine me.

i post code below since exceeds max message size if put post.


this part of code seems work fine:

code: [select]
int switchpin = 2;
int switchpin2 = 12;
int number1 = 0;
int number2 = 0;
int multnumber = 0;

int ledpins[] = {
  3,5,6,9,10,11};
int counter[] = {
  0,0,0,0,0,0};
int pinon[] = {
  0,0,0,0,0,0};

boolean lastbutton = low;
boolean lastbutton2 = low;
boolean currentbutton = low;
boolean currentbutton2 = low;
boolean stop = low;

void setup()
{
  pinmode(switchpin, input);
  pinmode(switchpin2, input);

  for( int = 0; < 6; i++)
  {
    pinmode(ledpins[i], output);
  }
}


void loop()
{
  do
  {
    currentbutton = debounce( lastbutton );
    currentbutton2 = debounce2 ( lastbutton2 );

    if(lastbutton == low && currentbutton == high)
    {
      number1 = number1 + 1;
      counter[0] = counter[0] + 1;

      //for 1 slot.
      if(counter[0] == 1)
      {
        pinon[0] = 128;
      }
      else if(counter[0] == 2)
      {
        pinon[0] = 254;
      }
      else if(counter[0] == 3)
      {
        counter[0] = 0;
        pinon[0] = 0;
        counter[1] = counter[1] + 1;
      }
      else
      {
        counter[0] = 0;
        pinon[0] = 0;
      }

      //for 2 slot.
      if(counter[1] == 1)
      {
        pinon[1] = 128;
      }
      else if(counter[1] == 2)
      {
        pinon[1] = 254;
      }
      else if(counter[1] == 3)
      {
        counter[1] = 0;
        pinon[1] = 0;
        counter[2] = counter[2] + 1;
      }
      else
      {
        counter[1] = 0;
        pinon[1] = 0;
      }

      //for slot 4
      if(counter[2] == 1)
      {
        pinon[2] = 128;
      }
      else if(counter[2] == 2)
      {
        pinon[2] = 254;
      }
      else if(counter[2] == 3)
      {
        counter[2] = 0;
        pinon[2] = 0;
        counter[3] = counter[3] + 1;
      }
      else
      {
        counter[2] = 0;
        pinon[2] = 0;
      }

      //for slot 8
      if(counter[3] == 1)
      {
        pinon[3] = 128;
      }
      else if(counter[3] == 2)
      {
        pinon[3] = 254;
      }
      else if(counter[3] == 3)
      {
        counter[3] = 0;
        pinon[3] = 0;
        counter[4] = counter[4] + 1;
      }
      else
      {
        counter[3] = 0;
        pinon[3] = 0;
      }

      //for slot 16
      if(counter[4] == 1)
      {
        pinon[4] = 128;
      }
      else if(counter[4] == 2)
      {
        pinon[4] = 254;
      }
      else if(counter[4] == 3)
      {
        counter[4] = 0;
        pinon[4] = 0;
        counter[5] = counter[5] + 1;
      }
      else
      {
        counter[4] = 0;
        pinon[4] = 0;
      }

      //for slot 32
      if(counter[5] == 1)
      {
        pinon[5] = 128;
      }
      else if(counter[5] == 2)
      {
        pinon[5] = 254;
      }
      else if(counter[5] == 3)
      {
        counter[5] = 0;
        pinon[5] = 0;
      }
      else
      {
        counter[5] = 0;
        pinon[5] = 0;
      }
    }

    for( int = 0; < 6; i++)
    {
      analogwrite(ledpins[i], pinon[i]);
    }

    if(lastbutton2 == low && currentbutton2 == high)
    {       
      stop = high;
    }

    lastbutton = currentbutton;
    lastbutton2 = currentbutton2;
  }
  while (stop == low);

  lastbutton = low;
  lastbutton2 = low;
  currentbutton = low;
  currentbutton2 = low;
  pinon[0] = 0;
  pinon[1] = 0;
  pinon[2] = 0;
  pinon[3] = 0;
  pinon[4] = 0;
  pinon[5] = 0;
  counter[0] = 0;
  counter[1] = 0;
  counter[2] = 0;
  counter[3] = 0;
  counter[4] = 0;
  counter[5] = 0;
  stop = low;

  do
  {
    currentbutton = debounce( lastbutton );
    currentbutton2 = debounce2 ( lastbutton2 );

    if(lastbutton == low && currentbutton == high)
    {
      number2 = number2 + 1;
      counter[0] = counter[0] + 1;

      //for 1 slot.
      if(counter[0] == 1)
      {
        pinon[0] = 128;
      }
      else if(counter[0] == 2)
      {
        pinon[0] = 254;
      }
      else if(counter[0] == 3)
      {
        counter[0] = 0;
        pinon[0] = 0;
        counter[1] = counter[1] + 1;
      }
      else
      {
        counter[0] = 0;
        pinon[0] = 0;
      }

      //for 2 slot.
      if(counter[1] == 1)
      {
        pinon[1] = 128;
      }
      else if(counter[1] == 2)
      {
        pinon[1] = 254;
      }
      else if(counter[1] == 3)
      {
        counter[1] = 0;
        pinon[1] = 0;
        counter[2] = counter[2] + 1;
      }
      else
      {
        counter[1] = 0;
        pinon[1] = 0;
      }

      //for slot 4
      if(counter[2] == 1)
      {
        pinon[2] = 128;
      }
      else if(counter[2] == 2)
      {
        pinon[2] = 254;
      }
      else if(counter[2] == 3)
      {
        counter[2] = 0;
        pinon[2] = 0;
        counter[3] = counter[3] + 1;
      }
      else
      {
        counter[2] = 0;
        pinon[2] = 0;
      }

      //for slot 8
      if(counter[3] == 1)
      {
        pinon[3] = 128;
      }
      else if(counter[3] == 2)
      {
        pinon[3] = 254;
      }
      else if(counter[3] == 3)
      {
        counter[3] = 0;
        pinon[3] = 0;
        counter[4] = counter[4] + 1;
      }
      else
      {
        counter[3] = 0;
        pinon[3] = 0;
      }

      //for slot 16
      if(counter[4] == 1)
      {
        pinon[4] = 128;
      }
      else if(counter[4] == 2)
      {
        pinon[4] = 254;
      }
      else if(counter[4] == 3)
      {
        counter[4] = 0;
        pinon[4] = 0;
        counter[5] = counter[5] + 1;
      }
      else
      {
        counter[4] = 0;
        pinon[4] = 0;
      }

      //for slot 32
      if(counter[5] == 1)
      {
        pinon[5] = 128;
      }
      else if(counter[5] == 2)
      {
        pinon[5] = 254;
      }
      else if(counter[5] == 3)
      {
        counter[5] = 0;
        pinon[5] = 0;
      }
      else
      {
        counter[5] = 0;
        pinon[5] = 0;
      }
    }

    if(lastbutton2 == low && currentbutton2 == high)
    {
      stop = high;
    }


    for( int = 0; < 6; i++)
    {
      analogwrite(ledpins[i], pinon[i]);
    }

    lastbutton = currentbutton;
    lastbutton2 = currentbutton2;

  }
  while (stop == low);


Arduino Forum > Using Arduino > Programming Questions > Doing multiplication in trinary not displaying correctly.


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial