Pages: [1]   Go Down
Author Topic: split a number up for the 3 digits  (Read 2515 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 217
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a number up to 999, and now I want to send that data to three 7 segment LEDS.

Is there some standard way that is used to do the math of ones tens etc, to break that number down into the single digit components to send to each display?

Thanks!

Logged

0
Offline Offline
Faraday Member
**
Karma: 13
Posts: 2857
ruggedcircuits.com
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
uint8_t ones,tens,hundreds;

hundreds = number/100;
number = number-hundreds*100;

tens = number/10;
ones = number-tens*10;

--
The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6899
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a number up to 999, and now I want to send that data to three 7 segment LEDS.

Is there some standard way that is used to do the math of ones tens etc, to break that number down into the single digit components to send to each display?

Thanks!



first=number/100;
second=number%100/10;
third=number%10;
Logged


Offline Offline
Full Member
***
Karma: 0
Posts: 217
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


This looks nice and easy.

Much appreciated.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6899
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No problem. This question is quite typical and gets asked like once a week. smiley-grin
Logged


Offline Offline
Full Member
***
Karma: 0
Posts: 217
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I assumed so, but could not find it on here.

Thanks.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 65
Posts: 6899
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I assumed so, but could not find it on here.

Thanks.

They don't always manifest the same way but this one I answered was pretty similar. Don't worry. It's a typical thing that we help newbies with the same questions over and over, as long as they're respecting the forum and provide enough information to get answers.

http://arduino.cc/forum/index.php/topic,72575.msg544298.html#msg544298
Logged


Pages: [1]   Go Up
Jump to: