왼쪽에 태종대에 있는 등대가 보인다.
졸려서 버스타고 태종대역에서 내리면 바로 보이는 작은 카페에서 차가운 더치커피를 샀다.
집으로 가는 길에 하늘이 이뻐서 찍었다.
날씨가 흐려서 오히려 더 좋았던 태종대. 덥지도 않고 사람도 별로 없었다. 태종대를 다 보고 나오려고 하는데 비가 내렸다.
꼭 한번 다시 가고 싶은 곳이다.
// Graphing sketch
// This program takes ASCII-encoded strings
// from the serial port at 9600 baud and graphs them. It expects values in the
// range 0 to 1023, followed by a newline, or newline and carriage return
// Created 20 Apr 2005
// Updated 18 Jan 2008
// by Tom Igoe
// This example code is in the public domain.
import processing.serial.*;
Serial myPort; // The serial port
int xPos = 1; // horizontal position of the graph
float easing = 2;
float easedVal=0;
void setup () {
// set the window size:
size(1200, 500);
// List all the available serial ports
println(Serial.list());
// I know that the first port in the serial list on my mac
// is always my Arduino, so I open Serial.list()[0].
// Open whatever port is the one you're using.
myPort = new Serial(this, Serial.list()[0], 9600);
// don't generate a serialEvent() unless you get a newline character:
myPort.bufferUntil('\n');
// set inital background:
background(0);
}
void draw () {
// everything happens in the serialEvent()
}
void serialEvent (Serial myPort) {
// get the ASCII string:
String inString = myPort.readStringUntil('\n');
if (inString != null) {
// trim off any whitespace:
inString = trim(inString);
// convert to an int and map to the screen height:
float inByte = float(inString);
float inByteColor = map(inByte, 0, 1023, 0, 255);
//Graph color
if (inByte > 200)
stroke((250+inByteColor)/2+127, 34, 255);
else if (inByte > 100 && inByte < 200)
stroke((100+inByteColor)/2+127, 34, 255);
else if (inByte > 50 && inByte < 100)
stroke((50+inByteColor)/2+127, 34, 255);
else
stroke(127,34,255);
inByte = map(inByte, 0, 1023, 0, height);
float targetVal = inByte;
easedVal = (targetVal) * easing;
// draw the line:
line(xPos, height, xPos, height-inByte);
// at the edge of the screen, go back to the beginning:
if (xPos >= width) {
xPos = 0;
background(0);
}
else {
// increment the horizontal position:
xPos++;
}
}
}
| cs |
#include <Servo.h> //header for servo motor
//This is for average
const int numReadings = 10;
int readings[numReadings]; // the readings from the analog input
int readIndex = 0; // the index of the current reading
int total = 0; // the running total
int average = 0; // the average
//This is for clap switch
int servoPin1 = 4, servoPin2 = 6; //servo1, servo2 pin
int soundSensorPin = A0;
int claps = 0; //count of clap
long detectionSpanInitial = 0;
long detectionSpan = 0;
boolean lightState = false;
Servo servo1, servo2;
void setup() {
Serial.begin(9600);
servo1.attach(servoPin1);
servo2.attach(servoPin2);
servo1.write(95); //Set the servo1 angle ( middle angle )
servo2.write(70); //Set the servo2 angle ( middle angle )
//Set for get an average
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}
void loop() {
//////////////////////////////////////////////////
//I used a code for get an average value from //
// https://www.arduino.cc/en/Tutorial/Smoothing //
//////////////////////////////////////////////////
// subtract the last reading:
total = total - readings[readIndex];
// read from the sensor:
readings[readIndex] = analogRead(soundSensorPin);
// add the reading to the total:
total = total + readings[readIndex];
// advance to the next position in the array:
readIndex = readIndex + 1;
// if we're at the end of the array...
if (readIndex >= numReadings)
// ...wrap around to the beginning:
readIndex = 0;
// calculate the average:
average = total / numReadings;
// send it to the computer as ASCII digits
//////////////////////////////////////////////////
//Now, I will use this average value. Because just the original anlaog value has a noise.
//////////////////////////////////////////////////////////////////////////////////
// I used a code from here. //
// http://en.code-bude.net/2014/12/08/how-to-build-a-clap-switch-using-arduino/ //
//////////////////////////////////////////////////////////////////////////////////
if (average >= 120) // detect clap
{
if (claps == 0) // If it is first clap,,
{
detectionSpanInitial = detectionSpan = millis(); // reset detectionSpanInitial, detectionSpan time
claps++;
}
else if (claps > 0 && millis()-detectionSpan >= 200) // minimum Span is 100 millisec.
{
detectionSpan = millis(); // update detectionSpan
claps++;
}
}
if (millis()-detectionSpanInitial >= 500) // Maximum Span is 400 milisec.
{
if (claps == 2) // If clap counts is 2, turn on or off the light.
{
if (!lightState)
{
lightState = true; // change state and turn on the light
servo1.write(135);
servo2.write(110);
delay(500); //delay for pushing the button
servo1.write(95);
servo2.write(70);
}
else if (lightState)
{
lightState = false; // change state and turn off the light
servo1.write(55);
servo2.write(30);
delay(500); //delay for pushing the button
servo1.write(95);
servo2.write(70);
}
delay(1000); //delay after change state
}
claps = 0; //reset clap count
}
Serial.println(average,DEC);
//////////////////////////////////////////////////////////////////////////////////
}
| cs |