기말 작업 계획.pptx
int ledApin = 22;
int ledBpin = 24;
int ledCpin = 26;
int ledDpin = 28;
int ledEpin = 30;
int ledFpin = 32;
int ledGpin = 34;
int ledHpin = 36;
int ledIpin = 38;
int enPin = 5; // Motor Enable
int in1Pin = 7; // Motor Dir
int in2Pin = 4; //
int input = A2; //Light Sensor
int lightValue = 0;const
int speakerOut = 10;
const int swPin = 2; // Switch
int count = 0;
int currentSwState = 0;
int lastSwState = 0;
#include "pitches.h"int melody1[ ] = {NOTE_G4, NOTE_A4, NOTE_G4, NOTE_E4, NOTE_C4, NOTE_A4, NOTE_G4, 0, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_C5, NOTE_B4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_D4, NOTE_B4, NOTE_A4, NOTE_G4, 0, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_G4, NOTE_A4, NOTE_E4 } ;int note1Durations[ ] = { 8, 4, 8, 4, 4, 4, 2, 4, 8, 8, 8, 8, 4, 4, 1, 8, 4, 8, 4, 4, 4, 2, 4, 8, 8, 8, 8, 4, 4, 1 } ;
void setup()
{
pinMode(ledApin, OUTPUT); pinMode(ledBpin, OUTPUT); pinMode(ledCpin, OUTPUT); pinMode(ledDpin, OUTPUT); pinMode(ledEpin, OUTPUT); pinMode(ledFpin, OUTPUT); pinMode(ledGpin, OUTPUT); pinMode(ledHpin, OUTPUT); pinMode(ledIpin, OUTPUT); pinMode(in1Pin, OUTPUT); pinMode(in2Pin, OUTPUT); pinMode(swPin, INPUT); Serial.begin(9600); pinMode(speakerOut, OUTPUT); analogWrite(enPin, 127) ; digitalWrite(in1Pin, HIGH) ; digitalWrite(in1Pin, LOW) ;}
void loop()
{
digitalWrite(ledApin, HIGH); digitalWrite(ledBpin, HIGH); digitalWrite(ledCpin, HIGH); digitalWrite(ledDpin, HIGH); digitalWrite(ledEpin, HIGH); digitalWrite(ledFpin, HIGH); digitalWrite(ledGpin, HIGH); digitalWrite(ledHpin, HIGH); digitalWrite(ledIpin, HIGH);
for (int thisNote = 0; thisNote < 31; thisNote++) {
int note1Duration = 1000/note1Durations[thisNote] ; tone(speakerOut, melody1[thisNote], note1Duration) ;
int pauseBetweenNotes = note1Duration * 1.3 ; delay(pauseBetweenNotes) ; noTone(speakerOut) ; } lightValue = analogRead(A2); if (lightValue >= 200) { digitalWrite(in1Pin, HIGH); digitalWrite(in2Pin, LOW); } else { digitalWrite(in1Pin, LOW); digitalWrite(in2Pin, HIGH); } for (int i =0; i<10; i++) { digitalWrite(ledApin, HIGH); digitalWrite(ledBpin, LOW); digitalWrite(ledCpin, HIGH); digitalWrite(ledDpin, LOW); digitalWrite(ledEpin, HIGH); digitalWrite(ledFpin, LOW); digitalWrite(ledGpin, HIGH); digitalWrite(ledHpin, LOW); digitalWrite(ledIpin, HIGH); delay (100) ; digitalWrite(ledApin, LOW); digitalWrite(ledBpin, HIGH); digitalWrite(ledCpin, LOW); digitalWrite(ledDpin, HIGH); digitalWrite(ledEpin, LOW); digitalWrite(ledFpin, HIGH); digitalWrite(ledGpin, LOW); digitalWrite(ledHpin, HIGH); digitalWrite(ledIpin, LOW); delay (100) ; }}
재료 : 폼보드, 펠트지, 아두이노, 브레드보드, LED, 스피커, 광센서, 모터, 스위치, 산타인형, 트리