Created
October 25, 2014 18:33
-
-
Save cyrildiagne/33b7fee7628d2dd80907 to your computer and use it in GitHub Desktop.
ATTiny Sketch for Portée/ modules
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
#define DST_IP "192.168.1.2" | |
#define DST_PORT 8888 | |
SoftwareSerial serial(3, 4); // RX, TX | |
int blinkPin = 0; | |
int vibrationDetectorPin = A1; | |
bool bConnected = false; | |
void setup() | |
{ | |
delay(1000); | |
serial.begin(19200); | |
delay(7000); | |
connect(); | |
delay(1000); | |
pinMode(blinkPin, OUTPUT); | |
digitalWrite(blinkPin, HIGH); | |
pinMode(vibrationDetectorPin, INPUT); | |
} | |
void loop() | |
{ | |
int val = digitalRead(vibrationDetectorPin); | |
if(val == 0) { | |
digitalWrite(blinkPin, LOW); | |
send(); | |
for(int i=0; i<5; i++) { | |
delay(50); | |
digitalWrite(blinkPin, HIGH); | |
delay(50); | |
digitalWrite(blinkPin, LOW); | |
} | |
} else { | |
digitalWrite(blinkPin, HIGH); | |
} | |
delay(1); | |
} | |
void connect() | |
{ | |
String cmd = "AT+CIPSTART=\"UDP\",\""; | |
cmd += DST_IP; | |
cmd += "\","; | |
cmd += DST_PORT; | |
cmd += "\r\n"; | |
serial.print(cmd); | |
} | |
void send() | |
{ | |
String cmd = "1/"; | |
serial.print("AT+CIPSEND="); | |
serial.print(cmd.length()); | |
serial.print("\r\n"); | |
delay(10); | |
serial.print(cmd); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment