【 Leonardo #1】 Let's collect Temperature & Brightness data to PC!
아두이노/5. 아두이노-프렌즈 2019. 5. 15. 17:49【 Leonardo #1】 Let's collect Temperature & Brightness value to PC!
Welcome to RasINO~!
In this chapter, we will learn how to use Arduino Leonardo board. Let's go~!
▶ The Goal :
1. You can see how to use the Leonardo board.
2. You can transfer the data from the temperature sensor & optical sensor (CDS) to the PC.
3. You can make your data into Excel charts or use them in a variety of ways.
▶ Connection diagram :
( Click image to enlarge )
▶ Coding and annotation :
/* Leonardo board Transfer temperature & brightness data to PC with Leonardo board */
#include <Keyboard.h>
const int TEMP = 0; // A0 port
const int CDS = 1; // A1 port
const int LED = 12;
const int BUTTON = 11;
boolean lastBtn = LOW;
boolean currentBtn = LOW;
boolean running = false;
int counter = 1;
void setup ( ) {
pinMode(LED, OUTPUT);
Keyboard.begin();
}
void loop ( ) {
currentBtn = debounce (lastBtn);
if (lastBtn == LOW && currentBtn == HIGH) // Click the button
{
running = !running; // Change state values backwards
}
lastBtn = currentBtn; // Update button state values
if (running) // Writing data
{
digitalWrite(LED, HIGH);
// The 'millis()' function returns the data in ms.
// So this function is used when the 'delay()' function is not available
if (millis()%1000 == 0) // Execute if statement every second
{
int temperature = analogRead(TEMP);
int brightness = analogRead(CDS);
float mVoltage = temperature*5000.0/1024.0; // Converted to Celsius temperature
float TempDotC = (mVoltage - 500) / 10.0; // Converted to Celsius temperature
Keyboard.print(counter); // Data numbering before each line
Keyboard.print(",");
Keyboard.print(TempDotC); // Temperature data
Keyboard.print(",");
Keyboard.print(brightness); // Brightness data
Keyboard.print("\n");
counter++;
}
}
else
{
digitalWrite(LED, LOW);
}
}
// Generate subfunctions to prevent button bouncing
boolean debounce (boolean last)
{
boolean current = digitalRead (BUTTON);
if(last != current)
{
delay(5);
current = digitalRead(BUTTON);
}
return current;
}
▶ Code download :
( The code is zip compressed.)
▶ Video lecture :
(Look in full screen view)
(You can watch it on YouTube.)
https://youtu.be/K-Dc5MqBYaI
'아두이노 > 5. 아두이노-프렌즈' 카테고리의 다른 글
【 레오나르도활용#3】어두워 지면 PC 화면 잠그기 (Leonardo) (3) | 2019.06.10 |
---|---|
【 Leonardo #3】 Visualize Temperature& Brightness Data on your PC with Leonardo (0) | 2019.05.28 |
【 레오나르도활용#3】 온도& 밝기값 PC로 비주얼화 하기 (Leonardo) (0) | 2019.05.24 |
【 레오나르도활용#2】 온도와 밝기값 PC로 수집하기 (Leonardo #2) (0) | 2019.05.15 |
【 레오나르도활용#1】 아두이노 레오나르도 보드 사용법 (Leonardo #1) (0) | 2019.05.13 |