Changes

H6105-D and H6103 basic input/output

2,419 bytes added, 12:09, 6 July 2017
Creata pagina con "= Desription = = Source Code = This is the source code in PAWN language of the '''H6105-D and H6103 basic input/output''' example: <syntaxhighlight lang="pawn"> /********..."
= Desription =


= Source Code =

This is the source code in PAWN language of the '''H6105-D and H6103 basic input/output''' example:

<syntaxhighlight lang="pawn">

/***************************************************************
*
* Basic Input Output - example
*
* program.p
*
***************************************************************/

// include the library for H6105-D
//
#include <hydlib_cp>

// define inputs
//
#define SWITCH_S1 MAKE_DIN_BOARD_CP(0)
#define SWITCH_S2 MAKE_DIN_BOARD_IO(0,0)

// define outputs
//
#define LAMP_L1 MAKE_OUT_BOARD_IO(0,0)
#define LAMP_L2 MAKE_OUT_BOARD_IO(0,1)

// main function
//
main()
{
// clear display
//
dClear();

// select system font
//
dFont( system5x7 );

// place cursor
//
dCursor( 0, 0 );

// print on display
//
dPrintf( "Basic IO" );

// set initial state of SWITCH_S1 and LAMP_L1
//
dCursor( 0, 10 );
if( DinRead( SWITCH_S1 ) )
{
dPrintf( "SWITCH_S1 ON " );
OutSet( LAMP_L1 );
}
else
{
dPrintf( "SWITCH_S1 OFF" );
OutClear( LAMP_L1 );
}

// set initial state of SWITCH_S2 and LAMP_L2
//
dCursor( 0, 20 );
if( DinRead( SWITCH_S2 ) )
{
dPrintf( "SWITCH_S2 ON " );
OutSet( LAMP_L2 );
}
else
{
dPrintf( "SWITCH_S2 OFF" );
OutClear( LAMP_L2 );
}

// declare an event container
//
new BASE_EVENT(ev);

// enable system events
//
SysEvEnable();

// main loop
//
for( ;; )
{
// get new event from queue
//
EventGet( ev );

// process some events
//
switch( ev.opcode )
{
// <script stop> command from console
//
case SevEmergExit:
{
// exit main loop
//
break;
}

// digital input activate
//
case SevDinActive:
{
// SWITCH_S1
//
if( ev.p0 == SWITCH_S1 )
{
dCursor( 0, 10 );
dPrintf( "SWITCH_S1 ON " );
OutSet( LAMP_L1 );
}

// SWITCH_S2
//
else if( ev.p0 == SWITCH_S2 )
{
dCursor( 0, 20 );
dPrintf( "SWITCH_S2 ON " );
OutSet( LAMP_L2 );
}
}

// digital input deactivate
//
case SevDinInactive:
{
// SWITCH_S1
//
if( ev.p0 == SWITCH_S1 )
{
dCursor( 0, 10 );
dPrintf( "SWITCH_S1 OFF" );
OutClear( LAMP_L1 );
}

// SWITCH_S2
//
else if( ev.p0 == SWITCH_S2 )
{
dCursor( 0, 20 );
dPrintf( "SWITCH_S2 OFF" );
OutClear( LAMP_L2 );
}
}
}
}

// program end
}

</syntaxhighlight>