hmkim
Published © GPL3+

Remote-Controlled PHPoC Mood Light

This is a Web page from PHPoC to control a mood light using the color picker.

BeginnerShowcase (no instructions)5 hours794
Remote-Controlled PHPoC Mood Light

Things used in this project

Hardware components

PHPoC Black
PHPoC Black
×1
Keyes RGB LED
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Story

Read more

Schematics

RGB LED with PHPoC Black

Code

index.php

PHP
1. Javascript library (refer to Script Turorials)
- jquery.js
Jqeury library + sizzle.js (https://sizzlejs.com/)

- colorpicker.js
Get RGB values that user picked

2. index.php
First, include Javacript libraries(jquery.js, colorpicker.js).
Then, read color palatte image(color.png)
When user select the color, that RGB color values shows at input box and select button's color changes to picked color.

After checking color, press the select button and send RGB value using POST.
That values are set at ht_pwm_setup function. Then RGB LED is on.
<!DOCTYPE html>
<?php
include_once "/lib/sd_340.php";
 
$red  = (int) _POST("red");
$green  = (int) _POST("green");
$blue  = (int) _POST("blue");
 
ht_pwm_setup(0, $red, 255); //red
ht_pwm_setup(1, $green, 255); //green
ht_pwm_setup(2, $blue, 255); //blue
 
?>
<html>
<head>
    <meta content="initial-scale=2.0, maximum-scale=1.0, minimum-scale=0.5, width=device-width, user-scalable=yes" name="viewport">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <style type="text/css">        
    * {
        margin: 0;
        padding: 0;
    }
    html {
        background-color: #eee;
    }
    .container {
        margin: 20px auto;
        text-align: justify;
        width: 400px;
    }

    /* colorpicker styles */
    .colorpicker {
        color: #000;
        font-size: 12px;
        width: 200px;
        margin: 0 auto;
    }
    #picker {
        cursor: crosshair;
        width: 200px;
        margin: 0 auto;
        border: 0;
    }
    .controls {
        width: 130px;
        margin: 0 auto;
    }
    .controls > div {
        margin-bottom: 5px;
        overflow: hidden;
        padding: 5px;
    }
    .controls label {
        float: left;
    }
    .controls > div input {
        border: 1px solid #2F2F2F;
        float: right;
        height: 20px;
        margin-left: 6px;
        text-align: center;
        text-transform: uppercase;
        width: 75px;
    }
    .preview {
        cursor: pointer;
        border-radius: 3px;
        box-shadow: 2px 2px 2px #444444;
        height: 40px;
        width: 100px;
        margin: 0 auto;
        text-align: center;
        line-height:40px;
    }
    </style>    
 
    <!-- add scripts -->
    <script src="jquery.js"></script>
    <script src="colorpicker.js"></script>
</head>
<body>
    <form name="main" method="post" action="index.php">
        <div class="container">
 
            <!-- colorpicker element -->
            <div class="colorpicker" style="display:none">
                <canvas id="picker" width="200" height="200"></canvas>
            </div>
            
            <div class="controls">
                <div><label>R</label> <input type="text" name="red" id="red" /></div>
                <div><label>G</label> <input type="text" name="green" id="green" /></div>
                <div><label>B</label> <input type="text" name="blue" id="blue" /></div>
            </div>
            <br />
            <!-- preview element -->
            <div class="preview" onclick="javascript:main.submit();">Select</div>
        </div>
    </form>    
</body>
</html>

Credits

hmkim

hmkim

1 project • 24 followers

Comments