2021.06.15.-2021.06.18.
β
μ λ ₯μ μΌμμνκ³Ό μ°μ μ λ°λμ νμν μλμ§μ΄λ€. μ κΈ°μ μλΉλμ
κΈμ¦νκ³ μμΌλ μ¬λλ€μ λΆνμν μ κΈ°λ₯Ό λλΉν λκ° μλ€.
β
μ΄λ₯Ό μλ°©νμ§ μλλ€λ©΄, λ λ€μ λκ·λͺ¨ μ μ μ¬ν λ±μΌλ‘ μ κΈ°λ₯Ό μ¬μ©ν μ μλ μν©μ λλ¬ν μ μλ€.
β
μ°λ¦¬λ μ΄μ κ°μ μν©μ νΌνκΈ° μν΄ λΆνμν μ κΈ° μλΉλ₯Ό μ€μ¬
μ κΈ°μκΈμ λν λΆλ΄μ μ€μ΄λ κ²κ³Ό νΈλ¦¬ν¨μ μΆκ΅¬νλ μ°κ΅¬λ₯Ό νλ €κ³ νλ€.
β
μ격μΌλ‘ μ μ΄κ° λλ μλλ‘μ΄λ μ±μ λ§λ€μ΄ μ€μκ°μΌλ‘ 릴λ μ΄μμ μλ μ¬λΆλ₯Ό νμΈνκ³ ,
μ¬μ©μκ° μ€μ ν΄λ μκ°μ μ λ±μ λΆμ΄ μΌμ§κ±°λ κΊΌμ§ μ μλλ‘ νλ€.
β
νμ΄λ¨Έ κΈ°λ₯μ μ 곡νμ¬ 10μ΄ λ€μ μ λ±μ΄ On λλ©° μλ μλ¦¬κ° ν¨κ» μ 곡λλ μ€κ³λ₯Ό λͺ©νλ‘ νλ€.
β
μ€κ³ μμ€ν ꡬμ±μ λ€μκ³Ό κ°λ€.
β


β
β


β
β

β
μλμ΄λ Έ μ½λλ λ€μκ³Ό κ°λ€.
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
#include <ESP8266.h>
#include <SPI.h>
#include "ESP8266.h"
#include <SoftwareSerial.h>
int ledPin2 = 4;
int ledPin3 = 5;
int ledPin4 = 6;
int ledPin5 = 7;
#define SSID "shj"
#define PASSWORD "11111111"
unsigned long cnt;
boolean t=false;
SoftwareSerial mySerial(11,10); /* RX:D11, TX:D10 */
ESP8266 wifi(mySerial);
void printUsage(uint8_t mux_id)
{
char buf[]="μ¬μ©κ°λ₯ν λͺ
λ Ήμ΄\n1 : LED μΌκΈ°\n2 : LED λκΈ°\nS : LED μνμ 보\n\n";
wifi.send(mux_id, buf, strlen(buf));
}
int melody[] = {
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_AS4, NOTE_AS4, NOTE_AS4, NOTE_AS4,
NOTE_D5, NOTE_D5, NOTE_D5, NOTE_D5,
NOTE_C5, NOTE_C5, NOTE_C5, NOTE_C5,
NOTE_F5, NOTE_F5, NOTE_F5, NOTE_F5,
NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5,
NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5,
NOTE_G5, NOTE_G5, NOTE_G5, NOTE_G5,
NOTE_C5, NOTE_AS4, NOTE_A4, NOTE_F4,
NOTE_G4, 0, NOTE_G4, NOTE_D5,
NOTE_C5, 0, NOTE_AS4, 0,
NOTE_A4, 0, NOTE_A4, NOTE_A4,
NOTE_C5, 0, NOTE_AS4, NOTE_A4,
NOTE_G4,0, NOTE_G4, NOTE_AS5,
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
NOTE_G4,0, NOTE_G4, NOTE_AS5,
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
NOTE_G4, 0, NOTE_G4, NOTE_D5,
NOTE_C5, 0, NOTE_AS4, 0,
NOTE_A4, 0, NOTE_A4, NOTE_A4,
NOTE_C5, 0, NOTE_AS4, NOTE_A4,
NOTE_G4,0, NOTE_G4, NOTE_AS5,
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5,
NOTE_G4,0, NOTE_G4, NOTE_AS5,
NOTE_A5, NOTE_AS5, NOTE_A5, NOTE_AS5
};
int noteDurations[] = {
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
8,8,8,8,
};
void setup(void)
{
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
digitalWrite( ledPin2, HIGH) ;
digitalWrite( ledPin3, LOW );
digitalWrite( ledPin4, LOW );
mySerial.begin(9600);
Serial.begin(9600);
Serial.print("setup begin\r\n");
Serial.print("FW Version:");
Serial.println(wifi.getVersion().c_str());
if (wifi.setOprToStationSoftAP()) {
Serial.print("to station + softap ok\r\n");
} else {
Serial.print("to station + softap err\r\n");
}
if (wifi.joinAP(SSID, PASSWORD)) {
Serial.print("Join AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Join AP failure\r\n");
}
if (wifi.enableMUX()) {
Serial.print("multiple ok\r\n");
} else {
Serial.print("multiple err\r\n");
}
if (wifi.startTCPServer(9000)) {
Serial.print("start tcp server ok\r\n");
} else {
Serial.print("start tcp server err\r\n");
}
if (wifi.setTCPServerTimeout(1000)) {
Serial.print("set tcp server timout 360 seconds\r\n");
} else {
Serial.print("set tcp server timout err\r\n");
}
Serial.print("setup end\r\n");
pinMode(LED_BUILTIN, OUTPUT);
}
void loop(void)
{
uint8_t buffer[128] = {0};
uint8_t mux_id;
uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer), 100);
if(t==true){
if((millis()>cnt+10*1000)){
digitalWrite( ledPin2, LOW );
for (int thisNote = 0; thisNote < 112; thisNote++) {
uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer), 100);
if(len>0)break;
int noteDuration = 750 / noteDurations[thisNote];
tone(ledPin5 , melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
noTone(ledPin5 );
}
t=false;
digitalWrite( ledPin2, HIGH );
}
}
if (len > 0) {
Serial.print("Status:[");
Serial.print(wifi.getIPStatus().c_str());
Serial.println("]");
Serial.print("Received from :");
Serial.print(mux_id);
Serial.print("[");
Serial.print("Received:[");
for(uint32_t i = 0; i < len; i++) {
Serial.print((char)buffer[i]);
}
Serial.print("]\r\n");
char command = buffer[0];
int ledStatus = digitalRead(LED_BUILTIN);
switch (command){
case '1':
digitalWrite( ledPin2, LOW) ;
break;
case '2':
digitalWrite( ledPin2, HIGH );
break;
case '3':
digitalWrite( ledPin3, LOW );
break;
case '4':
digitalWrite( ledPin3, HIGH );
break;
case '5':
digitalWrite( ledPin4, HIGH );
break;
case '6':
digitalWrite( ledPin4, LOW );
break;
case 'g':
cnt=millis();
t=true;
}
}
}
μλλ‘μ΄λ μ€νλμ€μ MainActivity.java
package com.example.myapplication;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
public class MainActivity extends AppCompatActivity {
public static Context context_main;
private TextView mConnectionStatus;
private ArrayAdapter<String> mConversationArrayAdapter;
private Button light_button1, light_button2, color_button1,color_button2;
private static final String TAG = "TcpClient";
private boolean isConnected = false;
public Switch light_switch, time_switch;
private String mServerIP = null;
private Socket mSocket = null;
private PrintWriter mOut;
private BufferedReader mIn;
private Thread mReceiverThread = null;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mConnectionStatus = (TextView)findViewById(R.id.connection_status_textview);
light_button1 = (Button)findViewById(R.id.button3);
light_button2 = (Button)findViewById(R.id.button4);
color_button1 = (Button)findViewById(R.id.button6);
color_button2 = (Button)findViewById(R.id.button7);
light_switch = (Switch)findViewById(R.id.switch1);
time_switch = (Switch)findViewById(R.id.switch4);
light_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
String sendMessage = "1";
if (!isConnected) showErrorDialog("μλ²λ‘ μ μλν λ€μ ν΄λ³΄μΈμ.");
else {
new Thread(new SenderThread(sendMessage)).start();
}
light_button1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String sendMessage = "3";
if (!isConnected) showErrorDialog("μλ²λ‘ μ μλν λ€μ ν΄λ³΄μΈμ.");
else {
new Thread(new SenderThread(sendMessage)).start();
}
}
});
light_button2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String sendMessage = "4";
if (!isConnected) showErrorDialog("μλ²λ‘ μ μλν λ€μ ν΄λ³΄μΈμ.");
else {
new Thread(new SenderThread(sendMessage)).start();
}
}
});
color_button1.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String sendMessage = "5";
if (!isConnected) showErrorDialog("μλ²λ‘ μ μλν λ€μ ν΄λ³΄μΈμ.");
else {
new Thread(new SenderThread(sendMessage)).start();
}
}
});
color_button2.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String sendMessage = "6";
if (!isConnected) showErrorDialog("μλ²λ‘ μ μλν λ€μ ν΄λ³΄μΈμ.");
else {
new Thread(new SenderThread(sendMessage)).start();
}
}
});
} else {
String sendMessage = "2";
if (!isConnected) showErrorDialog("μλ²λ‘ μ μλν λ€μ ν΄λ³΄μΈμ.");
else {
new Thread(new SenderThread(sendMessage)).start();
}
}
}
});
time_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
String sendMessage = "g";
if (!isConnected) showErrorDialog("μλ²λ‘ μ μλν λ€μ ν΄λ³΄μΈμ.");
else {
new Thread(new SenderThread(sendMessage)).start();
}
} else {
String sendMessage = "e";
if (!isConnected) showErrorDialog("μλ²λ‘ μ μλν λ€μ ν΄λ³΄μΈμ.");
else {
new Thread(new SenderThread(sendMessage)).start();
}
}
}
});
mConversationArrayAdapter = new ArrayAdapter<>( this,
android.R.layout.simple_list_item_1 );
new Thread(new ConnectThread("192.168.78.148", 9000)).start();
context_main=this;
}
@Override
protected void onDestroy() {
super.onDestroy();
isConnected = false;
}
private static long back_pressed;
@Override
public void onBackPressed(){
if (back_pressed + 2000 > System.currentTimeMillis()){
super.onBackPressed();
Log.d(TAG, "onBackPressed:");
isConnected = false;
finish();
}
else{
Toast.makeText(getBaseContext(), "νλ² λ λ€λ‘κ°κΈ°λ₯Ό λλ₯΄λ©΄ μ’
λ£λ©λλ€.", Toast.LENGTH_SHORT).show();
back_pressed = System.currentTimeMillis();
}
}
private class ConnectThread implements Runnable {
private String serverIP;
private int serverPort;
ConnectThread(String ip, int port) {
serverIP = ip;
serverPort = port;
mConnectionStatus.setText("connecting to " + serverIP + ".......");
}
@Override
public void run() {
try {
mSocket = new Socket(serverIP, serverPort);
mServerIP = mSocket.getRemoteSocketAddress().toString();
} catch( UnknownHostException e )
{
Log.d(TAG, "ConnectThread: can't find host");
}
catch( SocketTimeoutException e )
{
Log.d(TAG, "ConnectThread: timeout");
}
catch (Exception e) {
Log.e(TAG, ("ConnectThread:" + e.getMessage()));
}
if (mSocket != null) {
try {
mOut = new PrintWriter(new BufferedWriter(new OutputStreamWriter(mSocket.getOutputStream(), "UTF-8")), true);
mIn = new BufferedReader(new InputStreamReader(mSocket.getInputStream(), "UTF-8"));
isConnected = true;
} catch (IOException e) {
Log.e(TAG, ("ConnectThread:" + e.getMessage()));
}
}
runOnUiThread(new Runnable() {
@Override
public void run() {
if (isConnected) {
Log.d(TAG, "connected to " + serverIP);
mConnectionStatus.setText("connected to " + serverIP);
}else{
Log.d(TAG, "failed to connect to server " + serverIP);
mConnectionStatus.setText("failed to connect to server " + serverIP);
}
}
});
}
}
private class TimeThread implements Runnable {
private String time;
TimeThread(String time) {
this.time = time;
}
@Override
public void run() {
mOut.println(this.time);
mOut.flush();
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(TAG, "send message: " + time);
mConversationArrayAdapter.insert(time, 0);
}
});
}
}
private class SenderThread implements Runnable {
private String msg;
SenderThread(String msg) {
this.msg = msg;
}
@Override
public void run() {
mOut.println(this.msg);
mOut.flush();
runOnUiThread(new Runnable() {
@Override
public void run() {
Log.d(TAG, "send message: " + msg);
mConversationArrayAdapter.insert(msg, 0);
}
});
}
}
public void showErrorDialog(String message)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Error");
builder.setCancelable(false);
builder.setMessage(message);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
});
builder.create().show();
}
public void button8(View v)
{
Intent intent=new Intent(getApplicationContext(), AlarmActivity.class);
startActivity(intent); //μλ¦Ό μ€μ ν μ μλ μ μ°½ μ¬λκ±°..
}
}
RingtonePlayingService.java λ‘ μλ μμ μ μ¬μνλ€.
package com.example.myapplication;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Build;
import android.os.IBinder;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat;
import android.util.Log;
import android.widget.Switch;
public class RingtonePlayingService extends Service{
MediaPlayer mediaPlayer;
int startId;
boolean isRunning;
@Nullable
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
if (Build.VERSION.SDK_INT >= 26) {
String CHANNEL_ID = "default";
NotificationChannel channel = new NotificationChannel(CHANNEL_ID,
"Channel human readable title",
NotificationManager.IMPORTANCE_DEFAULT);
((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).createNotificationChannel(channel);
Notification notification = new NotificationCompat.Builder(this, CHANNEL_ID)
.setContentTitle("μλμμ")
.setContentText("μλμμ΄ μ¬μλ©λλ€.")
.setSmallIcon(R.mipmap.ic_launcher)
.build();
((MainActivity)MainActivity.context_main).light_switch.setChecked(true);
startForeground(1, notification);
}
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
String getState = intent.getExtras().getString("state");
assert getState != null;
switch (getState) {
case "alarm on":
startId = 1;
break;
case "alarm off":
startId = 0;
break;
default:
startId = 0;
break;
}
// μλμ μ¬μ X , μλμ μμ ν΄λ¦
if(!this.isRunning && startId == 1) {
mediaPlayer = MediaPlayer.create(this,R.raw.ouu);
mediaPlayer.start();
this.isRunning = true;
this.startId = 0;
}
// μλμ μ¬μ O , μλμ μ’
λ£ λ²νΌ ν΄λ¦
else if(this.isRunning && startId == 0) {
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.release();
this.isRunning = false;
this.startId = 0;
}
// μλμ μ¬μ X , μλμ μ’
λ£ λ²νΌ ν΄λ¦
else if(!this.isRunning && startId == 0) {
this.isRunning = false;
this.startId = 0;
}
// μλμ μ¬μ O , μλμ μμ λ²νΌ ν΄λ¦
else if(this.isRunning && startId == 1){
this.isRunning = true;
this.startId = 1;
}
else {
}
return START_NOT_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Log.d("onDestory() μ€ν", "μλΉμ€ νκ΄΄");
}
}
Alarm_Reciver.java λ₯Ό ν΅νμ¬ μ μ₯λ μλ μκ°μ λ°λλ€.
package com.example.myapplication;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.util.Log;
public class Alarm_Reciver extends BroadcastReceiver{
Context context;
@Override
public void onReceive(Context context, Intent intent) {
this.context = context;
// intentλ‘λΆν° μ λ¬λ°μ string
String get_yout_string = intent.getExtras().getString("state");
// RingtonePlayingService μλΉμ€ intent μμ±
Intent service_intent = new Intent(context, RingtonePlayingService.class);
// RingtonePlayinServiceλ‘ extra stringκ° λ³΄λ΄κΈ°
service_intent.putExtra("state", get_yout_string);
// start the ringtone service
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O){
this.context.startForegroundService(service_intent);
}else{
this.context.startService(service_intent);
}
}
}
AlarmActivity.java λ‘ μ¬μ©μ μλ μ€μ μ νλ€.
package com.example.myapplication;
import android.app.AlarmManager;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Switch;
import android.widget.TimePicker;
import android.widget.Toast;
import java.sql.Time;
import java.util.Calendar;
import java.util.GregorianCalendar;
public class AlarmActivity extends AppCompatActivity{
AlarmManager alarm_manager;
TimePicker alarm_timepicker;
Context context;
PendingIntent pendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm);
this.context = this;
// μλλ§€λμ μ€μ
alarm_manager = (AlarmManager) getSystemService(ALARM_SERVICE);
// νμνΌμ»€ μ€μ
alarm_timepicker = findViewById(R.id.time_picker);
// Calendar κ°μ²΄ μμ±
final Calendar calendar = Calendar.getInstance();
// μλ리μλ² intent μμ±
final Intent my_intent = new Intent(this.context, Alarm_Reciver.class);
// μλ μμ λ²νΌ
Button alarm_on = findViewById(R.id.btn_start);
alarm_on.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// calendarμ μκ° μ
ν
calendar.set(Calendar.HOUR_OF_DAY, alarm_timepicker.getHour());
calendar.set(Calendar.MINUTE, alarm_timepicker.getMinute());
// μκ° κ°μ Έμ΄
int hour = alarm_timepicker.getHour();
int minute = alarm_timepicker.getMinute();
Toast.makeText(AlarmActivity.this,"Alarm μμ " + hour + "μ " + minute + "λΆ",Toast.LENGTH_SHORT).show();
// reveiverμ string κ° λ겨주기
my_intent.putExtra("state","alarm on");
pendingIntent = PendingIntent.getBroadcast(AlarmActivity.this, 0, my_intent,
PendingIntent.FLAG_UPDATE_CURRENT);
// μλμ
ν
alarm_manager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
pendingIntent);
}
});
// μλ μ μ§ λ²νΌ
Button alarm_off = findViewById(R.id.btn_finish);
alarm_off.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(AlarmActivity.this,"Alarm μ’
λ£",Toast.LENGTH_SHORT).show();
// μλλ§€λμ μ·¨μ
alarm_manager.cancel(pendingIntent);
my_intent.putExtra("state","alarm off");
// μλμ·¨μ
sendBroadcast(my_intent);
}
});
}
}
β






β
β
[1] νκ΅μ λ ₯곡μ¬, γνκ΅μ λ ₯ν΅κ³γ, μλμ§κ²½μ μ°κ΅¬μ, γμλμ§μκΈν΅κ³γ
* μλ£ : μλμ§κ²½μ μ°κ΅¬μ, γ2020 μλμ§ν΅κ³μ°λ³΄γ 2021
[2]Lee, Y.-A., Kim, K.-C. and Han, S.-B. (2010) “μ격 μ λ ₯μ μ΄ λ° λκΈ°μ λ ₯ κ΄λ¦¬ κΈ°λ₯μ κ°λ μλ‘μ΄ μ€λ§νΈ μ€μμΉ μ€κ³,” νκ΅μ 보ν΅μ ννλ Όλ¬Έμ§. νκ΅μ 보ν΅μ νν, 14(10), pp. 2343–2350. doi: 10.6109/JKIICE.2010.14.10.2343.
[3] Tam LeMinh, “λ² νΈλ¨ μ€λ§νΈ μ€μμΉ, μΌλ§λ μ€λ§νΈν΄μ‘μκΉ?”, https://news.kotra.or.kr/user/globalBbs/kotranews/782/globalBbsDataView.do?setIdx=243&dataIdx=186959
[4] korta, “μ€λ§νΈ κ°μ μΌλ‘ κΎΈλ―Έλ μ€λ§νΈ ν, λ―Έκ΅μμ₯ μ§μΆ μ λ΅”, 2019-12, KOTRA 19-074
[5] κΉν¬μ±, “νμ보μ΄μ€, μμ±μΈμκ³Ό IoT κΈ°μ μ΅ν©λ μ¬μΌλ‘ μμ±μΈμ μ€λ§νΈ μ€μμΉ μΆμ”, 2016-04-05
[6] John, μ μλΆν ‘릴λ μ΄(Relay)'μ λν΄ μμ보기, http://Mechasolution.com
[7] 릴λ μ΄μ μ’ λ₯μ μ¬μ©λ°©λ², https://makernambo.com/47, 2019-01-21.
'νλ‘μ νΈ > Android' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[Android] GPSλ₯Ό μ΄μ©ν μ¬ν μ± (0) | 2023.01.02 |
---|---|
[Android] μ΄λ κ΄λ¦¬ μ± (0) | 2023.01.02 |