Control De Andon Con Arduino Por Serial
Enviado por Arduino123 • 11 de Marzo de 2015 • 3.144 Palabras (13 Páginas) • 357 Visitas
//#define _DEBUG
enum SwitchMode
{
Slow,
Normal,
Fast
};
enum LoopMode
{
SingleShot,
Bounce,
Loop
};
enum Pins
{
Red = 0,
Orange,
Green,
Blue
};
const int pTelephone = 15;
void DebugPrint( char* _strInfo )
{
#ifdef _DEBUG
Serial.println( _strInfo );
#endif
}
void DebugPrint( int _nInfo )
{
#ifdef _DEBUG
Serial.print( _nInfo );
Serial.print( ", " );
#endif
}
// The analogue have 17 values due to inverse square law on led brighness
static const byte MAX_INDEX = 16;
static const byte s_fadeValues[] = { 255, 180, 128, 90, 64, 45, 32, 23, 16, 12, 8, 6, 4, 3, 2, 1, 0 };
static const byte s_slowBlinkValues[] = { 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
static const byte s_fastBlinkValues[] = { 255, 255, 255, 255, 255, 0, 0, 0, 255, 255, 255, 255, 255, 0, 0, 0, 0 };
// the colors are red, orange, green and blue respectively
// serial light instructions
static const byte s_onCommand[] = { '!', '@', '#', '$' };
static const byte s_offCommand[] = { '1', '2', '3', '4' };
// output pins
static const byte s_pins[] = { 3, 5, 6, 9 };
// values (off)
volatile byte g_values[] = { MAX_INDEX, MAX_INDEX, MAX_INDEX, MAX_INDEX };
// step
volatile byte g_step[] = { 0, 0, 0, 0 };
// light operation modes
volatile SwitchMode g_eSwitchMode[] = { Normal, Normal, Normal, Normal };
volatile SwitchMode g_eCurrentSwitchMode = Normal;
volatile LoopMode g_eLoopMode[] = { SingleShot, SingleShot, SingleShot, SingleShot };
volatile LoopMode g_eCurrentLoopMode = SingleShot;
void setup( )
{
Serial.begin( 9600 );
// make it output
pinMode( s_pins[ Red ], OUTPUT );
pinMode( s_pins[ Orange ], OUTPUT );
pinMode( s_pins[ Green ], OUTPUT );
pinMode( s_pins[ Blue ], OUTPUT );
/*
pinMode( pTelephone, INPUT );
digitalWrite( pTelephone, LOW );
pinMode( 14, INPUT );
digitalWrite( 14, LOW );
pinMode( 20, INPUT );
digitalWrite( 20, LOW );
*/
// wait to make sure serial is initialized on the host
delay(1000);
DebugPrint( "initialization done, starting demo mode" );
demoMode( );
}
void loop( )
{
byte idx;
byte nCurrentPinValue;
// check if data has been sent from the computer:
if (Serial.available( ))
{
byte input;
// read the most recent byte (which will be from 0 to 255):
input = Serial.read( );
switch ( input )
{
// switch mode
...