ミニパトライト

Posted by atusi on 2013/11/26 in PC | Short Link

 工場にあるステータスを3色のランプで表示するパトライトを作ってみた。
 TvRockに仕込んで、録画中は赤、番組取得は黄色、なんにもしてない時は青が光るようにしてみた。

IMG_20131126_225622

Arduinoのスケッチ

int ledRedPin = 11; // LED connected to digital pin 13
int ledYellowPin = 10; // LED connected to digital pin 13
int ledBluePin = 9; // LED connected to digital pin 13

int signal = 0;

int red = 0x31;
int yellow = 0x32;
int blue = 0x33;
int all = 0x34;

void setup()
{
pinMode(ledRedPin, OUTPUT); // sets the digital pin as output
pinMode(ledYellowPin, OUTPUT); // sets the digital pin as output
pinMode(ledBluePin, OUTPUT); // sets the digital pin as output

Serial.begin(9600);

signal = ledBluePin;
}

void loop()
{
int num;

if ( Serial.available() > 0)
{
signal = Serial.read();
} else {
// signal = 0;
}

if ( signal == red )
{
digitalWrite(ledRedPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledRedPin, LOW); // sets the LED off
delay(1000); // waits for a second
} else if ( signal == yellow )
{
digitalWrite(ledYellowPin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledYellowPin, LOW); // sets the LED off
delay(1000); // waits for a second
} else if ( signal == blue )
{
digitalWrite(ledBluePin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledBluePin, LOW); // sets the LED off
delay(1000); // waits for a second
} else if ( signal == all )
{
digitalWrite(ledRedPin, HIGH); // sets the LED on
digitalWrite(ledYellowPin, HIGH); // sets the LED on
digitalWrite(ledBluePin, HIGH); // sets the LED on
delay(1000); // waits for a second
digitalWrite(ledRedPin, LOW); // sets the LED off
digitalWrite(ledYellowPin, LOW); // sets the LED off
digitalWrite(ledBluePin, LOW); // sets the LED off
delay(1000); // waits for a second
}
}

PCからコードを送るC#のプログラム

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO.Ports;

namespace comsend
{
class Program
{

static void Main(string[] args)
{
string program;
string port;
string value;

if ( args.Count() < 2 ) { Console.Write("No Parameter."); return; } // program = args[0]; port = args[0]; value = args[1]; if (port == "") { Console.Write("No com port."); return; } int BaudRate = 9600; Parity Parity = Parity.None; int DataBits = 8; StopBits StopBits = StopBits.One; SerialPort myPort = new SerialPort(port, BaudRate, Parity, DataBits, StopBits); myPort.Open(); myPort.Write(value); myPort.Close(); } } }

タグ:

Copyright © 2003-2024 いっちゃってる~日々 All rights reserved.
Shades-custom, v1.0, was grown from the Shades theme, v2.4.1, created by BuyNowShop.com.