모두의 아두이노란 책을 보고있습니다.
책에서 탭으로 스케치를 여러개 사용하여 모듈화가 가능하다고 하는데 실험을 해보니 왼쪽 프로그램만 실행되고 우측것은 동작을 하지 않습니다.
조언을 부탁합니다.
#Tap1 Trigger
/* Trigger Signal */
const int TRGPin = 7; // the number of the Trigger pin
const int ledPin = 12; // the number of the LED pin
const int Lamp1Pin = 13; // the number of the Lamp pin
const int Lamp2Pin = 11; // the number of the Lamp pin
const int Lamp3Pin = 10; // the number of the Lamp pin
int ledState = LOW; // the current state of the output pin
int TRGState = 0; // variables will change:
void setup() { // variable for reading the Trigger status
pinMode(TRGPin, INPUT); // initialize the Trigger pin as an input:
digitalWrite(TRGPin, HIGH); // variable for reading the Trigger status
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
pinMode(Lamp1Pin, OUTPUT); // initialize the Lamp1 pin as an output:
pinMode(Lamp2Pin, OUTPUT); // initialize the Lamp2 pin as an output:
pinMode(Lamp3Pin, OUTPUT); // initialize the Lamp3 pin as an output:
}
void loop() {
TRGState = digitalRead(TRGPin); // read the state of the Trigger value:
// check if the Trigger is pressed.
if (TRGState == ledState) { // if it is, the TriggerState is HIGH:
digitalWrite(ledPin, LOW); // turn LED on:
digitalWrite(Lamp1Pin, LOW); // turn Lamp1 on:
digitalWrite(Lamp2Pin, LOW); // turn Lamp2 on:
digitalWrite(Lamp3Pin, LOW); // turn Lamp3 on:
}
else {
digitalWrite(ledPin, HIGH); // turn LED off:
digitalWrite(Lamp1Pin, HIGH); // turn Lamp1 off:
digitalWrite(Lamp2Pin, HIGH); // turn Lamp2 off:
digitalWrite(Lamp3Pin, HIGH); // turn Lamp3 off:
}
}
#Tap2 Analog
/*
Analog input, analog output, serial output
아날로그 입력 단자를 읽어, 0에서 255의 범위로 결과를 맵핑하고,
출력 핀의 펄스 폭 변조(PWM)를 설정하고 그 결과를 사용한다.
또한 시리얼 모니터에 결과를 출력합니다.
The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground
created 29 Dec. 2008
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
// These constants won't change. They're used to give names
// to the pins used:
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to:
const int analogOutPin = 9; // Analog output pin that the LED is attached to:
int sensorValue = 0; // value read from the pot:
int outputValue = 0; // value output to the PWM (analog out):
//void setupVref() {
// Serial.begin(9600); // initialize serial communications at 9600 bps:}
void loopVref() {
sensorValue = analogRead(analogInPin); // read the analog in value:
outputValue = map(sensorValue, 0, 1023, 0, 255); // map it to the range of the analog out:
analogWrite(analogOutPin, outputValue); // change the analog out value:
//Serial.print("sensor = "); // print the results to the serial monitor:
//Serial.print(sensorValue);
//Serial.print("\t output = ");
//Serial.println(outputValue);
//delay(500); // wait 500 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
}
|