View unanswered posts | View active topics It is currently Mon Nov 12, 2018 6:34 pm



Reply to topic  [ 1 post ] 
 fit-statUSB: Color Explorer App 
Author Message

Joined: Mon May 28, 2012 12:25 pm
Posts: 104
Post fit-statUSB: Color Explorer App
Overview

How many distinct colors can fit-statUSB display? The answer to that question is 256 Red x 256 Green x 256 Blue which equals 16,777,216. Realistically, the average human eye can't discern that many colors, but a bit of fun can be had by trying.

The perl app included in this post provides the user with a simple method of quickly exploring the various colors which fit-statUSB can display via 3 slide controls (red, green, and blue). The resulting color combination is displayed both on-screen and by fit-statUSB. The app prominently displays the corresponding hex code. Should the user arrive at a desirable color, the hex code can be written down for further use in applications.



Examples

Shade of Purple
Attachment:
Color1.jpeg
Color1.jpeg [ 263.1 KiB | Viewed 366 times ]



Shade of Yellow
Attachment:
Color2.jpeg
Color2.jpeg [ 266.82 KiB | Viewed 366 times ]



Shade of Blue-Green
Attachment:
Color3.jpeg
Color3.jpeg [ 264.11 KiB | Viewed 366 times ]





Perl App

#!/usr/bin/perl -w
#
#fitStatColor.pl

# Darryl Hassell 8/14/2018

use Tk;
use Device::SerialPort;
use Time::HiRes ('sleep');

# Define & Initialize Variables

our $RedDec = 255;
our $GreenDec = 255;
our $Bluedec = 255;

our $RedHex = 'FF0000';
our $GreenHex = '00FF00';
our $BlueHex = '0000FF';

our $ColorString = '#FFFFFF';


# Configure Serial Port
my $port = Device::SerialPort -> new("/dev/ttyACM0");
$port -> baudrate(115200);
$port -> databits(8);
$port -> parity("none");
$port -> stopbits(1);
$port -> write_settings;

# Set Sleep Delay After Writes in Seconds
our $delay = 0.1;

#Initialize fit-statUSB to 10 mSec Fade
$port -> write("F10\n");
$port -> purge_rx;
sleep(0.5);

# Initialize fit-statUSB to Max Brightness White Then Off
$port -> write("#FFFFFF\n");
$port -> purge_rx;
sleep(1);
$port -> write("#000000\n");

# Create Main Window
$WinMain = MainWindow->new;
$WinMain -> resizable (0,0);

# Label Main Window
$myframe_label = $WinMain -> Frame ->pack();
$myframe_label -> Label (-text => 'fit-statUSB Color Explorer', -foreground => "black", -font => "helvetica 15 bold")->pack(-ipadx => 10,-ipady => 5);

# Create Window For All Controls
$myframe_Control = $WinMain -> Frame (-relief => 'groove', -bd => 5);
$myframe_Control -> Label (-text => 'Color Slide Controls', -foreground => "black", -font => "helvetica 12 bold")->pack(-ipadx => 110,-ipady => 5);

# Create Red Program Window and Slider
$myframe_Red = $myframe_Control -> Frame (-relief => 'groove', -bd => 5);

# Red Slider
$RedDec = 0;
$myframe_Red -> Scale(
-label => 'Red',
-font => 'helvetica 12 bold',
-foreground => "black",
-background => "#FF0000",
-orient => 'vertical',
-from => 255,
-to => 0,
-digits =>1,
-resolution => 1,
-tickinterval => 10,
-showvalue => 'yes',
-length => '4.0i',
-variable => \$RedDec,
-command => sub{ print "Red Decimal Value: $RedDec\n"; }
) -> pack( -side => 'left' );

$myframe_Red -> pack (-side => 'left');
$myframe_Red -> pack (-padx => 5, -pady => 5);


# Create Green Program Window and Slider
$myframe_Green = $myframe_Control -> Frame (-relief => 'groove', -bd => 5);


# Green Slider
$GreenDec = 0;
$myframe_Green -> Scale(
-label => 'Green',
-font => 'helvetica 12 bold',
-foreground => "black",
-background => "#00FF00",
-orient => 'vertical',
-from => 255,
-to => 0,
-digits =>1,
-resolution => 1,
-tickinterval => 10,
-showvalue => 'yes',
-length => '4.0i',
-variable => \$GreenDec,
-command => sub{ print "Green Decimal Value: $GreenDec\n"; }
) -> pack( -side => 'left' );

$myframe_Green -> pack (-side => 'left');
$myframe_Green -> pack (-padx => 5, -pady => 5);


# Create Blue Program Window and Slider
$myframe_Blue = $myframe_Control -> Frame (-relief => 'groove', -bd => 5);


# Blue Slider
$BlueDec = 0;
$myframe_Blue-> Scale(
-label => 'Blue',
-font => 'helvetica 12 bold',
-foreground => "white",
-background => "#0000FF",
-orient => 'vertical',
-from => 255,
-to => 0,
-digits =>1,
-resolution => 1,
-tickinterval => 10,
-showvalue => 'yes',
-length => '4.0i',
-variable => \$BlueDec,
-command => sub{ print "Blue Decimal Value: $BlueDec\n"; }
) -> pack( -side => 'left' );

$myframe_Blue -> pack (-side => 'left');
$myframe_Blue -> pack (-padx => 5, -pady => 5);

# Exit Button
$exitbutton = $myframe_Control -> Button (-text => 'Exit', -command => \&Exit, -foreground => 'white', -background => 'steelblue');
$exitbutton -> pack (-side => 'right', -padx => 10, -pady => 5,);

$myframe_Control -> pack (-side => 'top');
$myframe_Control -> pack (-padx => 10, -pady => 5);



# Create Window For Displaying Hex Value of Color
our $myframe_Color = $WinMain -> Frame (-bd => 75);
$myframe_Color -> Label (-textvariable => \$ColorString, -foreground => 'black', -font => "helvetica 32 bold")->pack(-ipadx => 125,-ipady => 5);
$myframe_Color -> pack (-side => 'top');
$myframe_Color -> pack (-padx => 10, -pady => 5);



$WinMain -> repeat(500, \&BuildColor);

MainLoop();

############### Subroutines ###############

sub BuildColor {

# Red Hex Value
if ($RedDec < 16){
$RedHex = "0".sprintf("%X", $RedDec);
}
else {
$RedHex = sprintf("%X", $RedDec);
}


# Green Hex Value
if ($GreenDec < 16){
$GreenHex = "0".sprintf("%X", $GreenDec);
}
else {
$GreenHex = sprintf("%X", $GreenDec);
}

# Blue Hex Value
if ($BlueDec < 16){
$BlueHex = "0".sprintf("%X", $BlueDec);
}
else {
$BlueHex = sprintf("%X", $BlueDec);
}

# Build Color String
$ColorString = "#".$RedHex.$GreenHex.$BlueHex;

$myframe_Color -> configure (-background => $ColorString);

print "$ColorString\n";

$port -> write("$ColorString\n");
$port -> purge_rx;
}



sub Exit {

$port -> write("#000000\n");
$port -> purge_rx;
sleep($delay);
exit;
}





Conclusions

fit-statUSB due to its very large number of available colors is suitable for a wide variety of applications. Whether for fun or for serious pursuits, fit-statUSB has something to offer where a wide palette of colors is required.


Wed Aug 15, 2018 3:23 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.