-
Notifications
You must be signed in to change notification settings - Fork 958
Add PIO 7-segment display example #714
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
@mjcross I've not tested this, as I don't have a bagful of transistors handy, but does this work? // Simple example of how to convert an integer between -999 and 9999
// into a 32-bit word representing up to four 7-segment digits.
//
uint32_t int_to_seven_segment (int num) {
uint32_t word = 0;
if (num < -999 || num > 9999) {
// number out of range, display 'E' symbol
// EDBGACF.
word = 0b11011010
} else {
if (num == 0) {
word = segments[0];
} else {
bool negative = num < 0;
if (negative) {
num *= -1;
}
int bitshift;
for (bitshift = 0; bitshift < 32 && num > 0; bitshift += 8) {
word |= segments[num % 10] << bitshift;
num /= 10;
}
if (negative) {
bitshift += 8;
// display '-' symbol
// EDBGACF.
word |= 0b00010000 << bitshift;
}
}
}
return word;
} |
@lurch yes: tested a couple of years ago when I wrote it, with tiny 7-segment displays that didn't need driver transistors ;-) The project I wrote it for needed up using an OLED display instead so it never got used. |
TBH if there's any bit of the project likely to cause issues it's probably the CMakeLists.txt files: I see at some point several of the example builds were adjusted to use |
Ahhh, sorry for the miscommunication - I wasn't asking "Does your function work?", I was asking "Does my suggested change to your function, to add support for displaying negative numbers, work?" 😂
It's so that if an example uses a hardware-feature that a particular board / chip / platform doesn't support, we don't try building that example for that chip. See e.g. https://github.com/raspberrypi/pico-examples/blob/master/rtc/CMakeLists.txt where we prevent the RTC examples from building for the RP2350 (as it doesn't have an RTC) or https://github.com/raspberrypi/pico-examples/blob/master/sha/CMakeLists.txt where we prevent the SHA examples from building for the RP2040 (as it doesn't have SHA256 hardware). P.S. I've just realised that you also need to edit the top-level |
Ahh - sorry! Didn't read carefully enough. That code looks nice - I'll check it this afternoon: tks! |
I like it! Turns out you don't need the |
You can simulate it with this slightly hacky code...
|
The output is actually rather cute
|
Hope the complex-looking circuit doesn't put people off: it's a really good use-case for the PIO. |
Add an example showing how to use the PIO to control a multiplexed 7-segment display.
@lurch this re-creates #375 as discussed, due to loss of the original repo