Skip to content

Add some example and delete repeat file #211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions examples/Face/FACESII_NeoPixelTest/FACESII_NeoPixelTest.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
neo pixel test

hardwware: M5StackFire

please install the Adafruit library first!
September 2018, ChrisMicro
*/

#include <Adafruit_NeoPixel.h>

#define M5STACK_FIRE_NEO_NUM_LEDS 10
#define M5STACK_FIRE_NEO_DATA_PIN 15

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(M5STACK_FIRE_NEO_NUM_LEDS, M5STACK_FIRE_NEO_DATA_PIN, NEO_GRB + NEO_KHZ800);

void setup()
{
pixels.begin();
}

void loop()
{

static int pixelNumber=0;// = random(0, M5STACK_FIRE_NEO_NUM_LEDS - 1);
pixelNumber++;
if(pixelNumber>9)pixelNumber=0;
int r = 1<<random(0, 7);
int g = 1<<random(0, 7);
int b = 1<<random(0, 7);

pixels.setPixelColor(pixelNumber, pixels.Color(r, g, b));
pixels.show();

delay(100);

}
41 changes: 41 additions & 0 deletions examples/Modules/GSM/GSM.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include <M5Stack.h>

void IotWriteCommand(char cmd[],char date[]){
char buf[256] = {0};

if(cmd == NULL)
sprintf(buf,"AT\r\n");
else if(date == NULL)
sprintf(buf,"AT+%s\r\n",cmd);
else
sprintf(buf,"AT+%s=%s\r\n",cmd,date);

Serial2.write(buf);
}
//AT+CSQ=?
void get_time(void){
IotWriteCommand("CSQ=?",NULL);
while(Serial2.available()){
uint8_t ch = Serial2.read();
Serial.write(ch);
M5.Lcd.write(ch);
}
}

void setup() {
M5.begin();

Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
pinMode(5, OUTPUT);
digitalWrite(5, 1);
}

void loop() {
if(M5.BtnA.wasReleased()){
M5.Lcd.fillScreen(TFT_BLACK);
M5.Lcd.setCursor(60,80,2);
get_time();
}
M5.update();
}
135 changes: 135 additions & 0 deletions examples/Modules/LORA868/LoRa868Duplex/LoRa868Duplex.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
/*
LoRa Duplex communication

Sends a message every half second, and polls continually
for new incoming messages. Implements a one-byte addressing scheme,
with 0xFF as the broadcast address.

Uses readString() from Stream class to read payload. The Stream class'
timeout may affect other functuons, like the radio's callback. For an

created 28 April 2017
by Tom Igoe
*/
#include <M5Stack.h>
#include <M5LoRa.h>

String outgoing; // outgoing message

byte msgCount = 0; // count of outgoing messages
byte localAddress = 0xFF; // address of this device
byte destination = 0xBB; // destination to send to

long lastSendTime = 0; // last send time
int interval = 1000; // interval between sends

void setup() {
M5.begin();
while (!Serial);

Serial.println("LoRa Duplex B");

// override the default CS, reset, and IRQ pins (optional)
LoRa.setPins();// set CS, reset, IRQ pin

if (!LoRa.begin(868E6)) { // initialize ratio at 868 MHz
Serial.println("LoRa init failed. Check your connections.");
while (true); // if failed, do nothing
}

Serial.println("LoRa init succeeded.");
}

void loop() {
if (millis() - lastSendTime > interval) {
String message = "HeLoRa World!"; // send a message
sendMessage(message);
Serial.println("Sending " + message);
M5.Lcd.setTextColor(BLUE);
M5.Lcd.println("Sending " + message);
lastSendTime = millis(); // timestamp the message
interval = random(1000) + 500; // 2-3 seconds
}

// parse for a packet, and call onReceive with the result:
onReceive(LoRa.parsePacket());

if(M5.BtnA.wasPressed()){
M5.Lcd.setCursor(0, 0);
M5.Lcd.clear(BLACK);
}

if(M5.BtnB.wasPressed()){
reinit();
}

M5.update();
}

void reinit(){
Serial.println("LoRa Duplex Reinitialization");

// override the default CS, reset, and IRQ pins (optional)
LoRa.setPins();// set CS, reset, IRQ pin

if (!LoRa.begin(868E6)) { // initialize ratio at 868 MHz
Serial.println("LoRa init failed. Check your connections.");
M5.Lcd.setCursor(0, 0);
M5.Lcd.setTextColor(RED);
M5.Lcd.println("Init failed!!!");
while (true); // if failed, do nothing
}

Serial.println("LoRa init succeeded.");
}

void sendMessage(String outgoing) {
LoRa.beginPacket(); // start packet
LoRa.write(destination); // add destination address
LoRa.write(localAddress); // add sender address
LoRa.write(msgCount); // add message ID
LoRa.write(outgoing.length()); // add payload length
LoRa.print(outgoing); // add payload
LoRa.endPacket(); // finish packet and send it
msgCount++; // increment message ID
}

void onReceive(int packetSize) {
if (packetSize == 0) return; // if there's no packet, return

// read packet header bytes:
int recipient = LoRa.read(); // recipient address
byte sender = LoRa.read(); // sender address
byte incomingMsgId = LoRa.read(); // incoming msg ID
byte incomingLength = LoRa.read(); // incoming msg length

String incoming = "";

while (LoRa.available()) {
incoming += (char)LoRa.read();
}

if (incomingLength != incoming.length()) { // check length for error
Serial.println("error: message length does not match length");
return; // skip rest of function
}

// if the recipient isn't this device or broadcast,
if (recipient != localAddress && recipient != 0xFF) {
Serial.println("This message is not for me.");
return; // skip rest of function
}

// if message is for this device, or broadcast, print details:
Serial.println("Received from: 0x" + String(sender, HEX));
Serial.println("Sent to: 0x" + String(recipient, HEX));
Serial.println("Message ID: " + String(incomingMsgId));
Serial.println("Message length: " + String(incomingLength));
Serial.println("Message: " + incoming);
Serial.println("RSSI: " + String(LoRa.packetRssi()));
Serial.println("Snr: " + String(LoRa.packetSnr()));
Serial.println();

M5.Lcd.setTextColor(YELLOW);
M5.Lcd.println("Message: " + incoming);
}
Loading