0% found this document useful (0 votes)
23 views13 pages

Fotos RSalvador

Uploaded by

lucasmoro125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views13 pages

Fotos RSalvador

Uploaded by

lucasmoro125
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Simple Demo

/**
The MIT License (MIT)

Copyright (c) 2018 by ThingPulse, Daniel Eichhorn


Copyright (c) 2018 by Fabrice Weinberg
Permission is hereby granted, free of charge, to any person
obtaining a copy
of this software and associated documentation files (the
"Software"), to deal
in the Software without restriction, including without
limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell
copies of the Software, and to permit persons to whom the
Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be


included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,


EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO
EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE
SOFTWARE.

ThingPulse invests considerable time and money to develop these


open source libraries.
Please support us by buying our products (and not the clones)
from
https://thingpulse.com

*/

// Include the correct display library

// For a connection via I2C using the Arduino Wire include:


#include <Wire.h> // Only needed for Arduino 1.6.5 and
earlier
#include "SSD1306Wire.h" // legacy: #include "SSD1306.h"
// OR #include "SH1106Wire.h" // legacy: #include "SH1106.h"

#include "pins_arduino.h"
// For a connection via I2C using brzo_i2c (must be installed)
include:
// #include <brzo_i2c.h> // Only needed for Arduino 1.6.5
and earlier
// #include "SSD1306Brzo.h"
// OR #include "SH1106Brzo.h"

// For a connection via SPI include:


// #include <SPI.h> // Only needed for Arduino 1.6.5
and earlier
// #include "SSD1306Spi.h"
// OR #include "SH1106SPi.h"

// Optionally include custom images


#include "images.h"

// Initialize the OLED display using Arduino Wire:


SSD1306Wire display(0x3c, SDA_OLED, SCL_OLED); // ADDRESS, SDA,
SCL - SDA_OLED and SCL_OLED are the pins from pins_arduino.h
where the Heltec connects the OLED display
// SSD1306Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL -
SDA and SCL usually populate automatically based on your board's
pins_arduino.h e.g.
https://github.com/esp8266/Arduino/blob/master/variants/nodemcu/pin
s_arduino.h
// SSD1306Wire display(0x3c, D3, D5); // ADDRESS, SDA, SCL - If
not, they can be specified manually.
// SSD1306Wire display(0x3c, SDA, SCL, GEOMETRY_128_32); //
ADDRESS, SDA, SCL, OLEDDISPLAY_GEOMETRY - Extra param required
for 128x32 displays.
// SH1106Wire display(0x3c, SDA, SCL); // ADDRESS, SDA, SCL

// Initialize the OLED display using brzo_i2c:


// SSD1306Brzo display(0x3c, D3, D5); // ADDRESS, SDA, SCL
// or
// SH1106Brzo display(0x3c, D3, D5); // ADDRESS, SDA, SCL

// Initialize the OLED display using SPI:


// D5 -> CLK
// D7 -> MOSI (DOUT)
// D0 -> RES
// D2 -> DC
// D8 -> CS
// SSD1306Spi display(D0, D2, D8); // RES, DC, CS
// or
// SH1106Spi display(D0, D2); // RES, DC
#define DEMO_DURATION 3000
typedef void (*Demo)(void);

int demoMode = 0;
int counter = 1;

/******************
* VextOn and VextOff are
* take right from Heltec.cpp.
* These functions turn power
* to the diplay on and off.
*
* displayReset() is from
* HT_Display.cpp in the Heltec
* code. It resets the display
*****************/
void VextON(void) {
pinMode(Vext, OUTPUT);
digitalWrite(Vext, LOW);
}

void VextOFF(void) //Vext default OFF


{
pinMode(Vext, OUTPUT);
digitalWrite(Vext, HIGH);
}

void displayReset(void) {
// Send a reset
pinMode(RST_OLED, OUTPUT);
digitalWrite(RST_OLED, HIGH);
delay(1);
digitalWrite(RST_OLED, LOW);
delay(1);
digitalWrite(RST_OLED, HIGH);
delay(1);
}

void setup() {
Serial.begin(115200);
while (!Serial) {
delay(100);
}
Serial.println();
Serial.println();

// This turns on and resets the OLED on the Heltec boards


VextON();
displayReset();
// Initialising the UI will init the display too.
display.init();

display.flipScreenVertically();
display.setFont(ArialMT_Plain_10);
}

void drawFontFaceDemo() {
// Font Demo1
// create more fonts at http://oleddisplay.squix.ch/
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "Hello world");
display.setFont(ArialMT_Plain_16);
display.drawString(0, 10, "Hello world");
display.setFont(ArialMT_Plain_24);
display.drawString(0, 26, "Hello world");
}

void drawTextFlowDemo() {
display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawStringMaxWidth(0, 0, 128,
"Lorem ipsum\n dolor sit amet,
consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt
ut labore.");
}

void drawTextAlignmentDemo() {
// Text alignment demo
display.setFont(ArialMT_Plain_10);

// The coordinates define the left starting point of the text


display.setTextAlignment(TEXT_ALIGN_LEFT);
display.drawString(0, 10, "Left aligned (0,10)");

// The coordinates define the center of the text


display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 22, "Center aligned (64,22)");

// The coordinates define the right end of the text


display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, 33, "Right aligned (128,33)");
}

void drawRectDemo() {
// Draw a pixel at given position
for (int i = 0; i < 10; i++) {
display.setPixel(i, i);
display.setPixel(10 - i, i);
}
display.drawRect(12, 12, 20, 20);

// Fill the rectangle


display.fillRect(14, 14, 17, 17);

// Draw a line horizontally


display.drawHorizontalLine(0, 40, 20);

// Draw a line horizontally


display.drawVerticalLine(40, 0, 20);
}

void drawCircleDemo() {
for (int i = 1; i < 8; i++) {
display.setColor(WHITE);
display.drawCircle(32, 32, i * 3);
if (i % 2 == 0) {
display.setColor(BLACK);
}
display.fillCircle(96, 32, 32 - i * 3);
}
}

void drawProgressBarDemo() {
int progress = (counter / 5) % 100;
// draw the progress bar
display.drawProgressBar(0, 32, 120, 10, progress);

// draw the percentage as String


display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 15, String(progress) + "%");
}

void drawImageDemo() {
// see http://blog.squix.org/2015/05/esp8266-nodemcu-how-to-
create-xbm.html
// on how to create xbm files
display.drawXbm(34, 14, WiFi_Logo_width, WiFi_Logo_height,
WiFi_Logo_bits);
}

Demo demos[] = { drawFontFaceDemo, drawTextFlowDemo,


drawTextAlignmentDemo, drawRectDemo, drawCircleDemo,
drawProgressBarDemo, drawImageDemo };
int demoLength = (sizeof(demos) / sizeof(Demo));
long timeSinceLastModeSwitch = 0;
void loop() {
// clear the display
display.clear();
// draw the current demo method
demos[demoMode]();

display.setFont(ArialMT_Plain_10);
display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, 54, String(millis()));
// write the buffer to the display
display.display();

if (millis() - timeSinceLastModeSwitch > DEMO_DURATION) {


demoMode = (demoMode + 1) % demoLength;
timeSinceLastModeSwitch = millis();
}
counter++;
delay(10);
}

Ping Pong

/*
RadioLib SX126x Ping-Pong Example

For default module settings, see the wiki page


https://github.com/jgromes/RadioLib/wiki/Default-
configuration#sx126x---lora-modem

For full API reference, see the GitHub Pages


https://jgromes.github.io/RadioLib/
*/

// include the library


#include <RadioLib.h>

// This allows predefined pins to be used. Compatible with Heltec


and Espressif libraries.
#include <pins_arduino.h>

// uncomment the following only on one


// of the nodes to initiate the pings
//#define INITIATING_NODE

// SX1262 has the following connections:


// NSS pin: 10
// DIO1 pin: 2
// NRST pin: 3
// BUSY pin: 9
// SX1262 radio = new Module(10, 2, 3, 9);
SX1262 radio = new Module(SS, DIO0, RST_LoRa, BUSY_LoRa);

// or using RadioShield
// https://github.com/jgromes/RadioShield
//SX1262 radio = RadioShield.ModuleA;

// or using CubeCell
//SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);

// save transmission states between loops


int transmissionState = RADIOLIB_ERR_NONE;

// flag to indicate transmission or reception state


bool transmitFlag = false;

// flag to indicate that a packet was sent or received


volatile bool operationDone = false;

// this function is called when a complete packet


// is transmitted or received by the module
// IMPORTANT: this function MUST be 'void' type
// and MUST NOT have any arguments!
#if defined(ESP8266) || defined(ESP32)
ICACHE_RAM_ATTR
#endif
void setFlag(void) {
// we sent or received a packet, set the flag
operationDone = true;
}

void setup() {
Serial.begin(115200);
while(!Serial){
delay();
}

// initialize SX1262 with default settings


Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}

// set the function that will be called


// when new packet is received
radio.setDio1Action(setFlag);

#if defined(INITIATING_NODE)
// send the first packet on this node
Serial.print(F("[SX1262] Sending first packet ... "));
transmissionState = radio.startTransmit("Hello World!");
transmitFlag = true;
#else
// start listening for LoRa packets on this node
Serial.print(F("[SX1262] Starting to listen ... "));
state = radio.startReceive();
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
#endif
}

void loop() {
// check if the previous operation finished
if(operationDone) {
// reset flag
operationDone = false;

if(transmitFlag) {
// the previous operation was transmission, listen for
response
// print the result
if (transmissionState == RADIOLIB_ERR_NONE) {
// packet was successfully sent
Serial.println(F("transmission finished!"));

} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);

}
// listen for response
radio.startReceive();
transmitFlag = false;

} else {
// the previous operation was reception
// print data and send another packet
String str;
int state = radio.readData(str);

if (state == RADIOLIB_ERR_NONE) {
// packet was successfully received
Serial.println(F("[SX1262] Received packet!"));

// print data of the packet


Serial.print(F("[SX1262] Data:\t\t"));
Serial.println(str);

// print RSSI (Received Signal Strength Indicator)


Serial.print(F("[SX1262] RSSI:\t\t"));
Serial.print(radio.getRSSI());
Serial.println(F(" dBm"));

// print SNR (Signal-to-Noise Ratio)


Serial.print(F("[SX1262] SNR:\t\t"));
Serial.print(radio.getSNR());
Serial.println(F(" dB"));

// wait a second before transmitting again


delay(1000);

// send another one


Serial.print(F("[SX1262] Sending another packet ... "));
transmissionState = radio.startTransmit("Hello World!");
transmitFlag = true;
}

}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy