#pragma num_alias_table_entries 14

IO_1 pulsewidth clock(7) io_speed;
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 nviSpeed;
network input SNVT_switch nviDirect;

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

int on = 0;
int freq = 0;

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

when(nv_update_occurs(nviSpeed))
{
	freq = nviSpeed.value;
	io_out(io_speed, (freq));
}

when(nv_update_occurs(nviDirect))
{
	io_out(io_direct, (nviDirect.value && nviDirect.state));
	on = (nviDirect.value && nviDirect.state);
}

when(io_changes(ioButton1) to 0)
{
	if(freq < 100)
	{
		freq = freq + 20;
		io_out(io_speed, (freq));
		nviSpeed.state = 1;
		nviSpeed.value = (short) freq * 2;
		nvoValue01.state = 1;
		nvoValue02.state = 0;
	}
	else
	{
		io_out(io_speed, (freq));
		nviSpeed.state = 1;
		nviSpeed.value = (short) freq * 2;
		nvoValue01.state = 1;
		nvoValue02.state = 0;
	}
}

when(io_changes(ioButton2) to 0)
{
	if(freq > 20)
	{
		freq = freq - 20;
		io_out(io_speed, (freq));
		nviSpeed.state = 1;
		nviSpeed.value = (short) freq * 2;
		nvoValue01.state =0;	
		nvoValue02.state =1;
	}
	else
	{
		io_out(io_speed, 0);
		freq = 0;
		nviSpeed.state = 0;		
		nviSpeed.value = 0;
		nvoValue01.state = 0;
		nvoValue02.state = 0;
	}
}

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

    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)