Making Things Interactive

February 5, 2008

Roman Numeral Counter

Filed under: 4: Counting Sensor Input,Gaku Sato — ponkotsu @ 3:24 pm

I have no video cam so this will be a text-only transmission.

The following code is for a simple button-input (+1/-1) counter.

It displays the current count (0~39) in roman numerals.

Symbols (I, V, X) are represented by differently colored LEDs (8 total).

It doesn’t do subtractive notation (IX instead of VIIII) though.
The tricky points were:
– making counter wait til button is let go before looking for next input;
(otherwise +1/-1 buttons on rapidfire)
– pin 1 = transfer signal and uncontrollable?
– insufficient voltage for 8 LEDs (maybe sketchy circuitry?)
– realizing all LEDs can use same resistor to ground (and general wiring…)
– not knowing that both test LEDs were blown out…!


int PinPower = 13;

int PinUp = 11;
int PinDown = 10;

int Pin01 = 9; // pin 1 remains on…?
int Pin02 = 2;
int Pin03 = 3;
int Pin04 = 4;
int Pin05 = 5;
int Pin10 = 6;
int Pin20 = 7;
int Pin30 = 8;

int count = 0;
int letGo = 0;

int count10 = 0;
int count05 = 0;
int count01 = 0;

void setup()
{
  Serial.begin(9600);

pinMode(PinPower, OUTPUT);

pinMode(PinUp, INPUT);
  pinMode(PinDown, INPUT);

pinMode(Pin01, OUTPUT);
  pinMode(Pin02, OUTPUT);
  pinMode(Pin03, OUTPUT);
  pinMode(Pin04, OUTPUT);
  pinMode(Pin05, OUTPUT);
  pinMode(Pin10, OUTPUT);
  pinMode(Pin20, OUTPUT);
  pinMode(Pin30, OUTPUT);

digitalWrite(PinPower, HIGH);
  digitalWrite(Pin01, LOW);
  digitalWrite(Pin02, LOW);
  digitalWrite(Pin03, LOW);
  digitalWrite(Pin04, LOW);
  digitalWrite(Pin05, LOW);
  digitalWrite(Pin10, LOW);
  digitalWrite(Pin20, LOW);
  digitalWrite(Pin30, LOW);
}

void loop()
{
  if(digitalRead(PinUp)==HIGH && letGo==0)
  {
  count = count + 1;
  if(count==40) {count = 39;}
  letGo = 1;
  }
  if(digitalRead(PinDown)==HIGH && letGo==0)
  {
  count = count - 1;
  if(count==-1) {count = 0;}
  letGo = 1;
  }
  if(digitalRead(PinUp)==LOW && digitalRead(PinDown)==LOW)
  { letGo = 0; }

count10 = count/10;
  count05 = (count-10*count10)/5;
  count01 = count-10*count10-5*count05;

if(count010) {digitalWrite(Pin01, HIGH);}
  if(count011) {digitalWrite(Pin02, HIGH);}
  if(count012) {digitalWrite(Pin03, HIGH);}
  if(count013) {digitalWrite(Pin04, HIGH);}
  if(count05==0) {digitalWrite(Pin05, LOW);}
  if(count05==1) {digitalWrite(Pin05, HIGH);}
  if(count100) {digitalWrite(Pin10, HIGH);}
  if(count101) {digitalWrite(Pin20, HIGH);}
  if(count102) {digitalWrite(Pin30, HIGH);}
}

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: