Timer 의 Interval 값을 조정하여 LED 이동속도를 조절하는 예제입니다.
동영상
코드 C#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using ZeoDotNetLib;
namespace ZEO_Flow { public partial class Form1 : Form { const int STEP = 25; int iStatus = 0; int NowStep = -STEP;
PIN_NAME pin1 = PIN_NAME.PA0 | PIN_NAME.PA2| PIN_NAME.PA4 | PIN_NAME.PA6 | PIN_NAME.PA8 | PIN_NAME.PA10 | PIN_NAME.PA16; PIN_NAME pin2 = PIN_NAME.PA1 | PIN_NAME.PA3 | PIN_NAME.PA5 | PIN_NAME.PA7 | PIN_NAME.PA9 | PIN_NAME.PA11; PIN_NAME pin3 = PIN_NAME.PB0 | PIN_NAME.PB2 | PIN_NAME.PB4 | PIN_NAME.PB6 | PIN_NAME.PB9 | PIN_NAME.PB11; PIN_NAME pin4 = PIN_NAME.PB1 | PIN_NAME.PB3 | PIN_NAME.PB5 | PIN_NAME.PB7 | PIN_NAME.PB8 | PIN_NAME.PB10;
ZeoLib ZEO = new ZeoLib(); public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { this.ZEO.Open(); this.ZEO.InitZeo(0); this.ZEO.PORT_DirOutputALL(); this.ZEO.Pin_Set(this.ZEO.PIN_ALL); }
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { this.ZEO.Close(); }
private void timer1_Tick(object sender, EventArgs e) { if (timer1.Interval < 200) { timer1.Interval += NowStep/10; } else { timer1.Interval += NowStep; }
if (timer1.Interval < 100) { NowStep = STEP; } else if (timer1.Interval > 1000) { NowStep = -STEP; }
Console.WriteLine("int:"+timer1.Interval.ToString() +", nowstep:"+NowStep.ToString() );
switch (iStatus) { case 0: this.ZEO.Pin_Reset(pin1); this.ZEO.Pin_Set(pin4); break; case 1: this.ZEO.Pin_Reset(pin2); this.ZEO.Pin_Set(pin1);
break; case 2: this.ZEO.Pin_Reset(pin3); this.ZEO.Pin_Set(pin2); break; case 3: this.ZEO.Pin_Reset(pin4); this.ZEO.Pin_Set(pin3); break; default: break; }
iStatus = (++iStatus)%4; } } } |
전체 코드 Visual C# 2008 용
'ZEO 시리즈' 카테고리의 다른 글
ZEO-S, 스위치로 LED ON/OFF, C# (0) | 2013.06.13 |
---|---|
ZEO-S, LED 연속으로 이동, C# (0) | 2013.06.08 |
ZEO-S ADC 샘플링 테스트 C# (0) | 2013.04.16 |
ZEO-IO BOARD – ZEO IO 실험 보드 (0) | 2013.04.10 |
ZEO-S 모듈로 서보모터 제어 (0) | 2012.11.16 |