먼저 부저를 아두이노와 연결시킨다.
# buzzer
= 5; // 부저를 5번 포트
const int buzzer
setup(){
void
pinMode(buzzer, OUTPUT); // 출력을 5번 포트로 내보냄
}
loop(){
void
tone(buzzer, 440, 100);
delay(2000); // 2초 쉼
noTone(buzzer);
}
#include <SoftwareSerial.h>
= A0; // 태양광 패널 인풋
int solar_input
setup() {
void Serial.begin(9600);
pinMode(solar_input, INPUT); // 태양광 전류 인풋
}
loop() {
void
int solar_value;= analogRead(solar_input);
solar_value
delay(1000);
Serial.print(" salor panel = ");
Serial.print(solar_value);
Serial.print("\n");
}
태양광 패널을 밝은 태양이 있는 곳과 어두운 곳을 옮겨갈 때 태양광 패널에서 생산하는 전략을 씨리얼 모니터를 통해 확인이 가능하다.
20:56:53.234 -> salor panel = 479
20:56:54.263 -> salor panel = 379
20:56:55.255 -> salor panel = 474
20:56:56.265 -> salor panel = 530
20:56:57.255 -> salor panel = 532
20:56:58.246 -> salor panel = 533
20:56:59.247 -> salor panel = 532
20:57:00.268 -> salor panel = 529
20:57:01.247 -> salor panel = 531
20:57:02.276 -> salor panel = 533
20:57:03.271 -> salor panel = 746
20:57:04.268 -> salor panel = 827
20:57:05.263 -> salor panel = 775
20:57:06.285 -> salor panel = 827
20:57:07.284 -> salor panel = 745
20:57:08.277 -> salor panel = 976
20:57:09.269 -> salor panel = 990
20:57:10.267 -> salor panel = 975
20:57:11.284 -> salor panel = 974
20:57:12.283 -> salor panel = 964
20:57:13.289 -> salor panel = 913
20:57:14.295 -> salor panel = 900
20:57:15.288 -> salor panel = 960
20:57:16.303 -> salor panel = 908
20:57:17.299 -> salor panel = 573
20:57:18.292 -> salor panel = 510
20:57:19.280 -> salor panel = 252
20:57:20.278 -> salor panel = 223
20:57:21.312 -> salor panel = 548
20:57:22.283 -> salor panel = 536
20:57:23.293 -> salor panel = 514
20:57:24.288 -> salor panel = 1
20:57:25.299 -> salor panel = 4
20:57:26.303 -> salor panel = 6
20:57:27.300 -> salor panel = 9
핀의 위치는 다음과 같다.
=
unsigned char LED_0F[] // 0 1 2 3 4 5 6 7 8 9 A b C d E F -
{0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x8C,0xBF,0xC6,0xA1,0x86,0xFF,0xbf
};4]; //用于LED的4位显示缓存
unsigned char LED[= 2;
int SCLK = 1;
int RCLK = 0; //这里定义了那三个脚
int DIO setup ()
void
{pinMode(SCLK,OUTPUT);
pinMode(RCLK,OUTPUT);
pinMode(DIO,OUTPUT); //让三个脚都是输出状态
}loop()
void
{0]=1;
LED[1]=2;
LED[2]=3;
LED[3]=4;
LED[while(1)
{LED4_Display ();
}
}
LED4_Display (void)
void
{*led_table; // 查表指针
unsigned char
unsigned char i;//显示第1位
= LED_0F + LED[0];
led_table = *led_table;
i LED_OUT(i);
LED_OUT(0x01);
digitalWrite(RCLK,LOW);
digitalWrite(RCLK,HIGH);
//显示第2位
= LED_0F + LED[1];
led_table = *led_table;
i LED_OUT(i);
LED_OUT(0x02);
digitalWrite(RCLK,LOW);
digitalWrite(RCLK,HIGH);
//显示第3位
= LED_0F + LED[2];
led_table = *led_table;
i LED_OUT(i);
LED_OUT(0x04);
digitalWrite(RCLK,LOW);
digitalWrite(RCLK,HIGH);
//显示第4位
= LED_0F + LED[3];
led_table = *led_table;
i LED_OUT(i);
LED_OUT(0x08);
digitalWrite(RCLK,LOW);
digitalWrite(RCLK,HIGH);
}
LED_OUT(unsigned char X)
void
{
unsigned char i;for(i=8;i>=1;i--)
{if (X&0x80)
{digitalWrite(DIO,HIGH);
} else
{digitalWrite(DIO,LOW);
}<<=1;
XdigitalWrite(SCLK,LOW);
digitalWrite(SCLK,HIGH);
} }