Hi guys...
Finally decided to release this, I have a python version too but that is unimportant to me.
It is a text mode "Dual_VU.sh" meter.
It actually calls dash
as the interpreter but change the shebang to suit yourselves.
It uses the bell character for overload per channel and looks like a dual vertical LED display.
It is written longhand to show how the image is built up per _frame_ and NOT as an exercise in algorithm building.
I suspect this is yet another first...
Enjoy...
#!/usr/local/bin/dash
# OR......
#!/bin/sh
# Dual_VU.sh
# Startup variable values here.
byteone=0
bytetwo=0
blank="(C)2016, issued as Public Domain, CC0 licence, B.Walker, G0LCU."
greenlines=blank
yellowlines=blank
redlines=blank
# Assuming pure ASCII only, primarily for CygWin.
unichar="**"
# Assuming UTF-8 is a default encoding, block graphics in HEX format.
#unichar="\xe2\x96\x88\xe2\x96\x88"
# Assuming UTF-8 is a default encoding, block graphics in octal format.
#unichar="\342\226\210\342\226\210"
spacer=" ____ "
# A default CygWin install does not have 'clear' nor 'tput', so rely on terminal escape codes instead.
# CygWin's 'mintty' conforms to a large subset of terminal escape codes.
clrscn()
{
printf "%b" "\033[0m\033[2J\033[H"
}
while true
do
# Run continuously and use Ctrl-C to STOP!
blank="\033[0m "
# Generate two byte values as though grabbed from a serial, parallel or USB port.
# E.G. The Arduino Diecimila Dev Board from USB as a multiple analogue source.
# byteone=$(( RANDOM % ( 256 / 16 ) )) # This is undefined in POSIX.
# bytetwo=$(( RANDOM % ( 256 / 16 ) )) # This is undefined in POSIX.
awk ' BEGIN \
{ srand()
while(1)
printf( "%d %d\n", ( 256 / 16 ) * rand(), ( 256 / 16 ) * rand() )
}' | while read -r byteone bytetwo
do
# Although this should never occur, don't allow any errors.
if [ "$byteone" -ge "15" ]
then
byteone=15
fi
if [ "$byteone" -le "0" ]
then
byteone=0
fi
if [ "$bytetwo" -ge "15" ]
then
bytetwo=15
fi
if [ "$bytetwo" -le "0" ]
then
bytetwo=0
fi
# Do a full, clean, clear screen and start looping.
clrscn
printf "%b\n" "\033[0mDual Four Bit Level Vertical Analogue Bar Graph Display, (VU meters)..."
echo ""
printf "Original copyright, (C)2016, now issued under the CC0 licence, B.Walker, G0LCU.\n"
echo ""
printf "%b\n" "$blank\033[1;31m15 __ __ ____ __ __ 15"
redlines="$blank\033[1;31m14 __ "
if [ "$byteone" -ge "15" ]
then
redlines="$redlines$unichar$spacer"
else
redlines="$redlines $spacer"
fi
if [ "$bytetwo" -ge "15" ]
then
redlines="$redlines$unichar __ 14"
else
redlines="$redlines __ 14"
fi
printf "%b\n" "$redlines"
redlines="$blank\033[1;31m13 __ "
if [ "$byteone" -ge "14" ]
then
redlines="$redlines$unichar$spacer"
else
redlines="$redlines $spacer"
fi
if [ "$bytetwo" -ge "14" ]
then
redlines="$redlines$unichar __ 13"
else
redlines="$redlines __ 13"
fi
printf "%b\n" "$redlines"
yellowlines="$blank\033[1;33m12 __ "
if [ "$byteone" -ge "13" ]
then
yellowlines="$yellowlines$unichar$spacer"
else
yellowlines="$yellowlines $spacer"
fi
if [ "$bytetwo" -ge "13" ]
then
yellowlines="$yellowlines$unichar __ 12"
else
yellowlines="$yellowlines __ 12"
fi
printf "%b\n" "$yellowlines"
yellowlines="$blank\033[1;33m11 __ "
if [ "$byteone" -ge "12" ]
then
yellowlines="$yellowlines$unichar$spacer"
else
yellowlines="$yellowlines $spacer"
fi
if [ "$bytetwo" -ge "12" ]
then
yellowlines="$yellowlines$unichar __ 11"
else
yellowlines="$yellowlines __ 11"
fi
printf "%b\n" "$yellowlines"
yellowlines="$blank\033[1;33m10 __ "
if [ "$byteone" -ge "11" ]
then
yellowlines="$yellowlines$unichar$spacer"
else
yellowlines="$yellowlines $spacer"
fi
if [ "$bytetwo" -ge "11" ]
then
yellowlines="$yellowlines$unichar __ 10"
else
yellowlines="$yellowlines __ 10"
fi
printf "%b\n" "$yellowlines"
greenlines="$blank\033[1;32m 9 __ "
if [ "$byteone" -ge "10" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "10" ]
then
greenlines="$greenlines$unichar __ 9"
else
greenlines="$greenlines __ 9"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 8 __ "
if [ "$byteone" -ge "9" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "9" ]
then
greenlines="$greenlines$unichar __ 8"
else
greenlines="$greenlines __ 8"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 7 __ "
if [ "$byteone" -ge "8" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "8" ]
then
greenlines="$greenlines$unichar __ 7"
else
greenlines="$greenlines __ 7"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 6 __ "
if [ "$byteone" -ge "7" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "7" ]
then
greenlines="$greenlines$unichar __ 6"
else
greenlines="$greenlines __ 6"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 5 __ "
if [ "$byteone" -ge "6" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "6" ]
then
greenlines="$greenlines$unichar __ 5"
else
greenlines="$greenlines __ 5"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 4 __ "
if [ "$byteone" -ge "5" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "5" ]
then
greenlines="$greenlines$unichar __ 4"
else
greenlines="$greenlines __ 4"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 3 __ "
if [ "$byteone" -ge "4" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "4" ]
then
greenlines="$greenlines$unichar __ 3"
else
greenlines="$greenlines __ 3"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 2 __ "
if [ "$byteone" -ge "3" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "3" ]
then
greenlines="$greenlines$unichar __ 2"
else
greenlines="$greenlines __ 2"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 1 __ "
if [ "$byteone" -ge "2" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines $spacer"
fi
if [ "$bytetwo" -ge "2" ]
then
greenlines="$greenlines$unichar __ 1"
else
greenlines="$greenlines __ 1"
fi
printf "%b\n" "$greenlines"
greenlines="$blank\033[1;32m 0 __ "
if [ "$byteone" -ge "1" ]
then
greenlines="$greenlines$unichar$spacer"
else
greenlines="$greenlines"'__'"$spacer"
fi
if [ "$bytetwo" -ge "1" ]
then
greenlines="$greenlines$unichar __ 0"
else
greenlines="$greenlines"'__ __ 0'
fi
printf "%b\n" "$greenlines"
# Print the two byte values onto the screen...
printf "\n%b %u%b %u... \n" "\033[1;34mByteone =" "$byteone" ", bytetwo =" "$bytetwo"
printf "%b" "\033[0mPress Ctrl-C to stop... "
# Ignore the 'sleep' command running in floating point mode and not being POSIX compliant,
# it is only here as a delay until......
# ......it can be removed if the code is modified to access real hardware to use these VU meters.
sleep 0.1
# Use the system bell(s) for either or both VU overloads.
if [ "$byteone" -eq "15" ] || [ "$bytetwo" -eq "15" ]
then
printf "\007"
fi
done
done
I am NOT uploading this anywhere else, so if there is any flak then I get it here... ;oD
Thanks to Don for his "POSIX random" input on another thread.