Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 4:5ea8c91f607f, committed 2019-03-27
- Comitter:
- stkim92
- Date:
- Wed Mar 27 06:50:17 2019 +0000
- Parent:
- 3:c9cd5d11484d
- Commit message:
- WIZnet-IoTShield-SENSOR_CDS v0.9
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Mar 25 10:11:25 2019 +0000
+++ b/main.cpp Wed Mar 27 06:50:17 2019 +0000
@@ -19,71 +19,22 @@
*
*/
-
#include <string>
#include "mbed.h"
-#define RET_OK 1
-#define RET_NOK -1
-#define DEBUG_ENABLE 1
-#define DEBUG_DISABLE 0
-#define ON 1
-#define OFF 0
-
-#define MAX_BUF_SIZE 1024
-
-#define BG96_APN_PROTOCOL_IPv4 1
-#define BG96_APN_PROTOCOL_IPv6 2
-#define BG96_DEFAULT_TIMEOUT 1000
-#define BG96_CONNECT_TIMEOUT 15000
-#define BG96_SEND_TIMEOUT 500
-#define BG96_RECV_TIMEOUT 500
-
-#define BG96_APN_PROTOCOL BG96_APN_PROTOCOL_IPv6
-#define BG96_DEFAULT_BAUD_RATE 115200
-#define BG96_PARSER_DELIMITER "\r\n"
-
-#define CATM1_APN_SKT "lte-internet.sktelecom.com"
-
-#define CATM1_DEVICE_NAME_BG96 "BG96"
-#define DEVNAME CATM1_DEVICE_NAME_BG96
-
-#define devlog(f_, ...) if(CATM1_DEVICE_DEBUG == DEBUG_ENABLE) { pc.printf("\r\n[%s] ", DEVNAME); pc.printf((f_), ##__VA_ARGS__); }
#define myprintf(f_, ...) {pc.printf("\r\n[MAIN] "); pc.printf((f_), ##__VA_ARGS__);}
-/* Pin configuraiton */
-// Cat.M1
-#define MBED_CONF_IOTSHIELD_CATM1_TX D8
-#define MBED_CONF_IOTSHIELD_CATM1_RX D2
-#define MBED_CONF_IOTSHIELD_CATM1_RESET D7
-#define MBED_CONF_IOTSHIELD_CATM1_PWRKEY D9
-
// Sensors
#define MBED_CONF_IOTSHIELD_SENSOR_CDS A0
#define MBED_CONF_IOTSHIELD_SENSOR_TEMP A1
-
-/* Debug message settings */
-#define BG96_PARSER_DEBUG DEBUG_DISABLE
-#define CATM1_DEVICE_DEBUG DEBUG_ENABLE
-
+#define LEDPIN D13
Serial pc(USBTX, USBRX); // USB debug
-UARTSerial *_serial; // Cat.M1 module
-
-DigitalOut _RESET_BG96(MBED_CONF_IOTSHIELD_CATM1_RESET);
-DigitalOut _PWRKEY_BG96(MBED_CONF_IOTSHIELD_CATM1_PWRKEY);
-AnalogIn tempVal(MBED_CONF_IOTSHIELD_SENSOR_TEMP);
+DigitalOut LED(LEDPIN);
+AnalogIn cdsVal(MBED_CONF_IOTSHIELD_SENSOR_CDS);
-float val = 0; // 온도 측정 값 넣을 변수
-float voltage = 0; // 전압 계산 값 넣을 변수
-float celsius = 0; // 섭씨 계산 값 넣을 변수
-float fahrenheit = 0; // 화씨 계산 값 넣을 변수
-
-bool flag_gettime = false;
-
-float getTemperature_F(float _celsius);
-float getTemperature_C(float _voltage);
+float val = 0; // CDS 측정 값 넣을 변수
void serialPcInit(void)
{
@@ -91,8 +42,6 @@
pc.format(8, Serial::None, 1);
}
-
-
// ----------------------------------------------------------------
// Main routine
// ----------------------------------------------------------------
@@ -106,49 +55,20 @@
myprintf("WIZnet IoT Shield for Arm MBED");
myprintf("LTE Cat.M1 Version");
myprintf("=================================================");
- myprintf(">> Sample Code: TEMP Test)");
+ myprintf(">> Sample Code: CDS Test)");
myprintf("=================================================\r\n");
while(1) {
- // read the value from the sensor:
- val = tempVal.read_u16()/100;
- // 실제 전압 계산
- // 0~5V의 값을 구하기 위해 아래와 같이 5를 곱하고 1024를 나눈다.
- // (Analog값 * IC에 걸리는 전압 / Analog 10bit 분해능(1024))
- // IC에 걸리는 전압은 측정기로 측정
-
- voltage = val * 4.95 / 1024;
- celsius = getTemperature_C(voltage);
- fahrenheit = getTemperature_F(celsius);
+ val = cdsVal.read_u16()/100;
+ //myprintf("Sensor value : %.2f", val);
+ wait_ms(50);
- wait_ms(1000);
- myprintf("[ Temperature Data ]");
- myprintf("Sensor value : %.2f", val);
- myprintf("Volt : %.2f mV", voltage);
-
- myprintf("Celsius temp : %.2f C", celsius);
- myprintf("Fahrenheit temp : %.2f F", fahrenheit);
- wait_ms(1000);
+ if(val > 512) { // 조도 저항 값이 낮기 때문에 아날로그 값이 높음
+ LED = 0;
+ } else { // 손가락으로 가리면 조도 저항값이 높아지기 때문에 아날로그 값이 낮아진다
+ LED = 1;
+ }
}
-
-
}
-
-
-float getTemperature_F(float _celsius)
-{
- // 섭씨에서 화씨 환산 -> (화씨온도 = 섭씽온*9/5+32)
- fahrenheit = celsius * 9.0 / 5.0 + 32.0;
- return fahrenheit;
-}
-
-float getTemperature_C(float _voltage)
-{
- // LM35는 섭씨 1도당 10mV의 전위차를 갖는다.
- // 센서핀의 전압이 0.28V라면 280mV이므로 온도는 28도씨.
- // 100을 곱해서 섭씨 온도로 나타냄
- celsius = voltage * 100.0;
- return celsius;
-}