-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharduino_bluetooth.ino
More file actions
62 lines (47 loc) · 1.07 KB
/
Copy patharduino_bluetooth.ino
File metadata and controls
62 lines (47 loc) · 1.07 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
/*
NSAC - Near Space Arduino Course
Spring 2017
UPC Space Program
Code to show serial data treatment based in a non-interrupt software
*/
#include <SoftwareSerial.h>
SoftwareSerial BTserial(2, 3); // Rx and Tx of your Arduino
char c[100];
int i = 0;
bool input = false;
void setup()
{
Serial.begin(9600);
Serial.println("Arduino is ready");
Serial.println("Remember to select Both NL & CR in the serial monitor");
BTserial.begin(9600);
}
void loop()
{
delay(500);
if (BTserial.available()){
input = true;
while(BTserial.available()){
c[i] = BTserial.read();
i++;
}
}
if(input){
// We write through our Arduino Serial port (USB connected) what we sent.
Serial.println("Input detected, you sent:");
Serial.println(c);
// We write to out mobile phone
BTserial.print("You sent: ");
BTserial.println(c);
//We see what can we do with our data
if(!strcmp(c,"on")){
//do something
Serial.println("Shots fired");
BTserial.println("Shots fired");
}
//reset variables
input = false;
i = 0;
memset(c,0, sizeof(c));
}
}