int led 3 int brightness 0 int increment

  • Slides: 19
Download presentation

int led = 3; int brightness = 0; int increment = 1; analog. Write을

int led = 3; int brightness = 0; int increment = 1; analog. Write을 통해 구동되는 핀은 void setup() { 력으로 선언하지 않아도 된다. } void loop() { if(brightness > 255) { increment = -1; } else if(brightness < 1) { increment = 1; } brightness = brightness + increment; analog. Write(led, brightness); delay(10); } 출

int led. Pins[] = {2, 3, 4, 5, 6, 7, 8, 9}; void setup()

int led. Pins[] = {2, 3, 4, 5, 6, 7, 8, 9}; void setup() { for(int i=0; i<8; i++) { pin. Mode(led. Pins[i], OUTPUT); } } void loop() { for(int i=0; i<8; i++) { digital. Write(led. Pins[i], HIGH); delay(100); } for(int i =7; i>=0; i--) { digital. Write(led. Pins[i] , LOW); delay(100); } }

QA~QH = 출력 SER = data핀 (2번) SRCLK = clock핀 (3번) RCLK = latch핀

QA~QH = 출력 SER = data핀 (2번) SRCLK = clock핀 (3번) RCLK = latch핀 (4번) OE = reset(5 V) RSCLR = enable input(GND)

int datapin = 2; int clockpin = 3; int latchpin = 4; byte data

int datapin = 2; int clockpin = 3; int latchpin = 4; byte data = 0; void setup() { pin. Mode(datapin, OUTPUT); pin. Mode(clockpin, OUTPUT); pin. Mode(latchpin, OUTPUT); } void loop() { for(int i = 0; i<=7; i++) { shift. Write(i, HIGH); delay(100); }

for(int i = 7; i>=0; i--) { shift. Write(i, LOW); delay(100); } } void

for(int i = 7; i>=0; i--) { shift. Write(i, LOW); delay(100); } } void shift. Write(int desired. Pin, boolean desired. State) { bit. Write(data, desired. Pin, desired. State); shift. Out(datapin, clockpin, MSBFIRST, data); digital. Write(latchpin, HIGH); digital. Write(latchpin, LOW); }

#include <Servo. h> Servo motor 1; void setup() { motor 1. attach(9); } void

#include <Servo. h> Servo motor 1; void setup() { motor 1. attach(9); } void loop() { for(int position = 0; position<=180; position +=2) { motor 1. write(position); delay(20); } for(int position =180; position >=0; position -=2) { motor 1. write(position); delay(20); } }

int speed. Pin = 3; int motor 1 APin = 6; int motor 2

int speed. Pin = 3; int motor 1 APin = 6; int motor 2 APin = 7; int speed_value_motor 1 = 127; void setup() { pin. Mode(speed. Pin, OUTPUT); pin. Mode(motor 1 APin, OUTPUT); pin. Mode(motor 2 APin, OUTPUT); } void loop() { digital. Write(motor 1 APin, LOW); digital. Write(motor 2 APin, HIGH); analog. Write(speed. Pin, speed_value_motor 1); }

int button 1 Pin=2; int led. Pin=13; void setup() { pin. Mode(button 1 Pin,

int button 1 Pin=2; int led. Pin=13; void setup() { pin. Mode(button 1 Pin, INPUT); pin. Mode(led. Pin, OUTPUT); } void loop() { int button 1 State; button 1 State = digital. Read(button 1 Pin); if (button 1 State == LOW) { digital. Write(led. Pin, HIGH); } else { digital. Write(led. Pin, LOW); } }

int signal = 4; int onoff; void setup() { Serial. begin(9600); } void loop()

int signal = 4; int onoff; void setup() { Serial. begin(9600); } void loop() { onoff = digital. Read(signal); Serial. println(onoff); }