-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTask 1.1P
More file actions
119 lines (95 loc) · 2.62 KB
/
Task 1.1P
File metadata and controls
119 lines (95 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/27764efa-fdac-41f0-bc36-1a809a660c61
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
- No variables have been created, add cloud variables on the Thing Setup page
to see them declared here
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
// digital pin 2 has a pushbutton attached to it. Give it a name:
int pushButton = 2;
// Turn on LED to simulate a morse code 'dash'
void dash() {
digitalWrite(LED_BUILTIN, HIGH);
delay(300);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
// Turn on LED to simulate a morse code 'dot'
void dot() {
digitalWrite(LED_BUILTIN, HIGH);
delay(100);
digitalWrite(LED_BUILTIN, LOW);
delay(100);
}
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop() {
ArduinoCloud.update();
// read the input pin:
int buttonState = digitalRead(pushButton);
// if button is pressed play morse code
if (buttonState == 1)
{
// Morse code: 'b' -...
dash();
dot();
dot();
dot();
delay(300);
// Morse code: 'e' .
dot();
delay(300);
// Morse code: 'n' -.
dash();
dot();
delay(300);
// Morse code: 'j' .---
dot();
dash();
dash();
dash();
delay(300);
// Morse code: 'a' .-
dot();
dash();
delay(300);
// Morse code: 'm' --
dash();
dash();
delay(300);
// Morse code: 'i' ..
dot();
dot();
delay(300);
// Morse code: 'n' -.
dash();
dot();
delay(300);
}
}