'What unicode characters are best for drawing a squarewave in a string
I am trying to represent a square wave pulse train in a string, from an array of stored GPIO events and timings. the code is working but I need better Unicode characters for the transitions.
this is my current method
public String waveform()
{
String s = "";
int pulses;
int pulseWidth;
pulseWidth = events.get(1).duration; //mostly right!
for (RF433Event e: events)
{
pulses = e.duration/pulseWidth;
if (e.gpioEvent.getEdge() == PinEdge.RISING)
{
// rising edge so for the duration it was low
for (int i = 0; i<pulses; i++) s = s+'_';
s = s+"\u02E9";
} else
{
// falling edge so for the duration it was high
for (int i = 0; i<pulses; i++) s = s+"\u0305";
s = s+"\u02E5";
}
}
return s;
}
The output looks like this in the Intellij console window
but strangely is not appearing on the RPi, do I need to install something else on the Pi?
Solution 1:[1]
After much experimentation this works for me
public String waveform()
{
String s = "";
int pulses;
int pulseWidth;
// Characters tried for drawing the pulse train
// Low line - "_", "\u0332" Combining Low Line, "\uFF3F"; FULLWIDTH LOW LINE
// High line - "\u0305" COMBINING OVERLINE, "\u203E" over line
// Vertical - "\u20D2" COMBINING LONG VERTICAL LINE OVERLAY, "\u007C" Vertical line, "\u02E9" MODIFIER LETTER EXTRA-LOW TONE BAR
if (events.get(0).duration > 50000) {return "Excessive duration in pluse 0 "+events.get(0).duration;}
pulseWidth = 100; //gives a reasonable pulse train
for (RF433Event e: events)
{
pulses = e.duration/pulseWidth;
if (e.gpioEvent.getEdge() == PinEdge.RISING)
{
// rising edge so for the duration it was low
for (int i = 0; i<pulses; i++) s = s+ "_";
s = s+"\u20D2";
} else
{
// falling edge so for the duration it was high
for (int i = 0; i<pulses; i++) s = s+"\u0305";
s = s+"\u20D2";
}
}
return s;
}
Solution 2:[2]
I like the idea of using "combining characters", but find them harder to edit. Here are other unicode options I've used or tried.
- box drawings (light or heavy), which (as noted) need 2 rows:
1 ?????? ??????
0 ??? ??? ??? ???
- "lower one eighth block" (2581) with "lower three quarters block" (2586) or "full block" (2588). (Depending on font and line spacing, "full block" can reach the previous line.)
??????????
??????????
- "solidus" (slash), "reverses solidus" (backslash), "horizontal scan line 1" (23BA), and "horizontal scan line 9" (23BD) - for non-vertical transitions.
?????\???????????/?????\??
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | gjwo |
Solution 2 | Clif Kussmaul |