#pragma num_alias_table_entries 14

IO_1 pulsewidth clock(7) io_on_off;
IO_2 output bit io_direct;

IO_4 input bit ioButton1;
IO_5 input bit ioButton2;
IO_6 input bit ioButton3;

network input SNVT_switch nviUp;
network input SNVT_switch nviDown;
network input SNVT_switch nviDirect;

network output SNVT_switch nvoValue01;
network output SNVT_switch nvoValue02;
network output SNVT_switch nvoValue03;

int freq=0;

when(reset)
{
	io_out(io_on_off, 0);
	io_out(io_direct, 0);
}

when(nv_update_occurs(nviUp))
{
	if(freq < 100)
	{
		freq = freq + 20;
		io_out(io_on_off, (freq));
	}
	else
	{
		io_out(io_on_off, (freq));
	}
}

when(nv_update_occurs(nviDown))
{
	if(freq > 0)
	{
		freq = freq - 20;
		io_out(io_on_off, (freq));
	}
	else
	{
		io_out(io_on_off, 0);
		io_out(io_direct, 0);
	}
}

when(nv_update_occurs(nviDirect))
{
	if(freq == 0)
	{
		nvoValue03.value = 0;
		nvoValue03.state = 0;
	}
	else
	{
		io_out(io_direct, (nviDirect.value && nviDirect.state));
	}
}

when(io_changes(ioButton1) to 0)
{
	nvoValue01.state = !nvoValue01.state;
	nvoValue01.value = nvoValue01.state ? (short) 200:0;
}

when(io_changes(ioButton2) to 0)
{
	nvoValue02.state = !nvoValue02.state;
	nvoValue02.value = nvoValue02.state ? (short) 200:0;
}

when(io_changes(ioButton3) to 0)
{
	nvoValue03.state = !nvoValue03.state;
	nvoValue03.value = nvoValue03.state ? (short) 200:0;
}

    Source: geocities.com/hk/cloud_fan_school/Program/Motor

               ( geocities.com/hk/cloud_fan_school/Program)                   ( geocities.com/hk/cloud_fan_school)                   ( geocities.com/hk)