'2013/06'에 해당되는 글 3건

  1. 2013.06.13 ZEO-S, 스위치로 LED ON/OFF, C#
  2. 2013.06.08 ZEO-S, LED 연속으로 이동, C#
  3. 2013.06.06 ZEO-S, LED 이동 속도 조절, C#

 

스위치(버튼)의 입력을 받아 LED 를 ON/OFF 하는 예제입니다.

스위치의 눌림 상태에 따라 LED ON 위치가 변경되는 것을 알 수 있습니다.


스위치(버튼)의 눌림 상태를 읽는 방법은 아래 코드와 같이 3가지 방법이 있습니다.



 

 

 

 

 

 

 

 

 

 

 

코드 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 WATInputOutput

{

public partial class Form1 : Form

{

#region ZEO-IO Pin Define

const PIN_NAME D1 = PIN_NAME.PA0;

const PIN_NAME D2 = PIN_NAME.PA1;

const PIN_NAME D3 = PIN_NAME.PA2;

const PIN_NAME D4 = PIN_NAME.PA3;

const PIN_NAME D5 = PIN_NAME.PA4;

const PIN_NAME D6 = PIN_NAME.PA5;

const PIN_NAME D7 = PIN_NAME.PA6;

const PIN_NAME D8 = PIN_NAME.PA7;

const PIN_NAME D9 = PIN_NAME.PA8;

const PIN_NAME D10 = PIN_NAME.PA9;

const PIN_NAME D11 = PIN_NAME.PA10;

const PIN_NAME D12 = PIN_NAME.PA11;

const PIN_NAME D13 = PIN_NAME.PA16;

const PIN_NAME D14 = PIN_NAME.PB0;

const PIN_NAME D15 = PIN_NAME.PB1;

const PIN_NAME D16 = PIN_NAME.PB2;

const PIN_NAME D17 = PIN_NAME.PB3;

const PIN_NAME D18 = PIN_NAME.PB4;

const PIN_NAME D19 = PIN_NAME.PB5;

const PIN_NAME D20 = PIN_NAME.PB6;

const PIN_NAME D21 = PIN_NAME.PB7;

const PIN_NAME D22 = PIN_NAME.PB8;

const PIN_NAME D23 = PIN_NAME.PB9;

const PIN_NAME D24 = PIN_NAME.PB10;

const PIN_NAME D25 = PIN_NAME.PB11;

 

 

const PIN_NAME SW1 = PIN_NAME.PA12;

const PIN_NAME SW2 = PIN_NAME.PA13;

const PIN_NAME SW3 = PIN_NAME.PA14;

const PIN_NAME SW4 = PIN_NAME.PA15;

 

const PIN_NAME SW5 = PIN_NAME.PB12;

const PIN_NAME SW6 = PIN_NAME.PB13;

const PIN_NAME SW7 = PIN_NAME.PB14;

const PIN_NAME SW8 = PIN_NAME.PB15;

 

#endregion

 

 

 

PIN_NAME pin1 = D1 | D2| D3;

PIN_NAME pin2 = D4 | D5 | D6;

PIN_NAME pin3 = D7 | D8 | D9;

PIN_NAME pin4 = D10 | D11 | D12 | D13;

PIN_NAME pin5 = D14 | D15 | D17;

PIN_NAME pin6 = D16 | D18 | D19;

PIN_NAME pin7 = D20 | D21 | D22;

PIN_NAME pin8 = D23 | D24 | D25;

 

// ZEO-S 인스턴스

ZeoLib ZEO = new ZeoLib();

 

 

public Form1()

{

InitializeComponent();

}

 

private void Form1_Load(object sender, EventArgs e)

{

// ZEO 초기화

this.ZEO.Open();

if (this.ZEO.IsOpened)

{

this.ZEO.InitZeo(0);

this.ZEO.Pin_Set(this.ZEO.PIN_ALL);

this.ZEO.PORT_DirOutputALL();

// 스위치를 입력으로 설정

this.ZEO.PORT_DirInput(SW1 | SW2 | SW3 | SW4 | SW5 | SW6 | SW7 | SW8 );

}

 

}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

// ZEO 닫기

if (this.ZEO.IsOpened)

this.ZEO.Close();

}

 

private void timer1_Tick(object sender, EventArgs e)

{

if (!this.ZEO.IsOpened)

{

Console.WriteLine("ZEO-S 가 연결되어 있지 않습니다.");

return;

}

 

// 모든 포트의 값을 읽어

UInt32[] uiData = this.ZEO.ReadPortAll();

 

//////////////////////////////////////////////////

// 방법1

 

// SW1 눌리면

if (this.ZEO.PA12this.ZEO.Pin_Set(pin1);

else this.ZEO.Pin_Reset(pin1);

 

// SW2 눌리면

if (this.ZEO.PA13this.ZEO.Pin_Set(pin2);

else this.ZEO.Pin_Reset(pin2);

 

// SW3 눌리면

if (this.ZEO.PA14this.ZEO.Pin_Set(pin3);

else this.ZEO.Pin_Reset(pin3);

 

// SW4 눌리면

if (this.ZEO.PA15this.ZEO.Pin_Set(pin4);

else this.ZEO.Pin_Reset(pin4);

 

 

/////////////////////////////////////////////

// 방법2

 

 

// SW5 눌리면

this.ZEO.Pin_Write(pin5this.ZEO.PB12);

 

// SW6 눌리면

this.ZEO.Pin_Write(pin6this.ZEO.PB13);

 

 

//////////////////////////////////////

// 방법3

 

// SW7 눌리면

if ((uiData[1] & 0x4000) == 0x4000) this.ZEO.Pin_Set(pin7);

else this.ZEO.Pin_Reset(pin7);

 

// SW8 눌리면

if ((uiData[1] & 0x8000) == 0x8000) this.ZEO.Pin_Set(pin8);

else this.ZEO.Pin_Reset(pin8);

 

}

}

}

 

 

 

 

전체 코드 Visual C# 2008 용

다운로드

 

출처: http://whiteat.com/163865 

 

 

'ZEO 시리즈' 카테고리의 다른 글

ZEO-S PWM 펄스를 Pulse Counter로 읽기, C#  (0) 2013.09.02
ZEO-S Pulse Counter, C#  (0) 2013.08.29
ZEO-S, LED 연속으로 이동, C#  (0) 2013.06.08
ZEO-S, LED 이동 속도 조절, C#  (0) 2013.06.06
ZEO-S ADC 샘플링 테스트 C#  (0) 2013.04.16
Posted by WhiteAT
,

 

Timer 를 이용하여 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_Flow2

{

public partial class Form1 : Form

{

// LED 상태

int iStatus = 0;

 

// ZEO-S 인스턴스

ZeoLib ZEO = new ZeoLib();

 

 

public Form1()

{

InitializeComponent();

}

 

private void Form1_Load(object sender, EventArgs e)

{

// ZEO 초기화

this.ZEO.Open();

if (this.ZEO.IsOpened)

{

this.ZEO.InitZeo(0);

this.ZEO.PORT_DirOutputALL();

this.ZEO.Pin_Set(this.ZEO.PIN_ALL);

}

}

 

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

// ZEO 닫기

if (this.ZEO.IsOpened)

this.ZEO.Close();

}

 

private void timer1_Tick(object sender, EventArgs e)

{

if (!this.ZEO.IsOpened)

{

Console.WriteLine("ZEO-S 가 연결되어 있지 않습니다.");

return;

}

 

switch (iStatus)

{

case 0: this.ZEO.Pin_Reset(PIN_NAME.PA0); break;

case 1: this.ZEO.Pin_Reset(PIN_NAME.PA2); break;

case 2: this.ZEO.Pin_Reset(PIN_NAME.PA4); break;

case 3: this.ZEO.Pin_Reset(PIN_NAME.PA6); break;

 

case 4: this.ZEO.Pin_Set(PIN_NAME.PA0); break;

case 5: this.ZEO.Pin_Reset(PIN_NAME.PA8); break;

case 6: this.ZEO.Pin_Set(PIN_NAME.PA2); break;

case 7: this.ZEO.Pin_Reset(PIN_NAME.PA10); break;

case 8: this.ZEO.Pin_Set(PIN_NAME.PA4); break;

case 9: this.ZEO.Pin_Reset(PIN_NAME.PA16); break;

case 10: this.ZEO.Pin_Set(PIN_NAME.PA6); break;

case 11: this.ZEO.Pin_Reset(PIN_NAME.PA1); break;

 

case 12: this.ZEO.Pin_Set(PIN_NAME.PA8); break;

case 13: this.ZEO.Pin_Reset(PIN_NAME.PA3); break;

case 14: this.ZEO.Pin_Set(PIN_NAME.PA10); break;

case 15: this.ZEO.Pin_Reset(PIN_NAME.PA5); break;

case 16: this.ZEO.Pin_Set(PIN_NAME.PA16); break;

case 17: this.ZEO.Pin_Reset(PIN_NAME.PA7); break;

 

 

case 18: this.ZEO.Pin_Set(PIN_NAME.PA1); break;

case 19: this.ZEO.Pin_Reset(PIN_NAME.PA9); break;

case 20: this.ZEO.Pin_Set(PIN_NAME.PA3); break;

case 21: this.ZEO.Pin_Reset(PIN_NAME.PA11); break;

case 22: this.ZEO.Pin_Set(PIN_NAME.PA5); break;

case 23: this.ZEO.Pin_Reset(PIN_NAME.PB0); break;

 

 

case 24: this.ZEO.Pin_Set(PIN_NAME.PA7); break;

case 25: this.ZEO.Pin_Reset(PIN_NAME.PB2); break;

case 26: this.ZEO.Pin_Set(PIN_NAME.PA9); break;

case 27: this.ZEO.Pin_Reset(PIN_NAME.PB4); break;

case 28: this.ZEO.Pin_Set(PIN_NAME.PA11); break;

case 29: this.ZEO.Pin_Reset(PIN_NAME.PB6); break;

 

case 30: this.ZEO.Pin_Set(PIN_NAME.PB0); break;

case 31: this.ZEO.Pin_Reset(PIN_NAME.PB9); break;

 

case 32: this.ZEO.Pin_Set(PIN_NAME.PB2); break;

case 33: this.ZEO.Pin_Reset(PIN_NAME.PB11); break;

case 34: this.ZEO.Pin_Set(PIN_NAME.PB4); break;

case 35: this.ZEO.Pin_Reset(PIN_NAME.PB1); break;

case 36: this.ZEO.Pin_Set(PIN_NAME.PB6); break;

case 37: this.ZEO.Pin_Reset(PIN_NAME.PB3); break;

case 38: this.ZEO.Pin_Set(PIN_NAME.PB9); break;

case 39: this.ZEO.Pin_Reset(PIN_NAME.PB5); break;

case 40: this.ZEO.Pin_Set(PIN_NAME.PB11); break;

case 41: this.ZEO.Pin_Reset(PIN_NAME.PB7); break;

case 42: this.ZEO.Pin_Set(PIN_NAME.PB1); break;

case 43: this.ZEO.Pin_Reset(PIN_NAME.PB8); break;

case 44: this.ZEO.Pin_Set(PIN_NAME.PB3); break;

case 45: this.ZEO.Pin_Reset(PIN_NAME.PB10); break;

 

case 46: this.ZEO.Pin_Set(PIN_NAME.PB5); break;

case 47: this.ZEO.Pin_Reset(PIN_NAME.PA0); break;

case 48: this.ZEO.Pin_Set(PIN_NAME.PB7); break;

case 49: this.ZEO.Pin_Reset(PIN_NAME.PA2); break;

case 50: this.ZEO.Pin_Set(PIN_NAME.PB8); break;

case 51: this.ZEO.Pin_Reset(PIN_NAME.PA4); break;

case 52: this.ZEO.Pin_Set(PIN_NAME.PB10); break;

default:

iStatus = 2;

 

break;

}

 

iStatus++;

 

}

}

}

 

 

 

전체 코드 Visual C# 2008 용

 

 다운로드



  

출처:  http://docs.whiteat.com/?p=396


'ZEO 시리즈' 카테고리의 다른 글

ZEO-S Pulse Counter, C#  (0) 2013.08.29
ZEO-S, 스위치로 LED ON/OFF, C#  (0) 2013.06.13
ZEO-S, LED 이동 속도 조절, C#  (0) 2013.06.06
ZEO-S ADC 샘플링 테스트 C#  (0) 2013.04.16
ZEO-IO BOARD – ZEO IO 실험 보드  (0) 2013.04.10
Posted by WhiteAT
,

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 용


 다운로드




출처: http://whiteat.com/154626



 

'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
Posted by WhiteAT
,