Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RFM69.h>
- #include <RFM69_ATC.h>
- #include <SPIFlash.h>
- #include <SPI.h>
- #include "U8glib.h"
- U8GLIB_SSD1306_128X32 u8g(U8G_I2C_OPT_NONE);
- #define NODEID 1 //unique for each node on same network
- #define NETWORKID 100 //the same on all nodes that talk to each other
- #define FREQUENCY RF69_433MHZ
- #define ENCRYPTKEY "syauqiEncryptKey" //exactly the same 16 characters/bytes on all nodes!
- #define IS_RFM69HW_HCW //uncomment only for RFM69HW/HCW! Leave out if you have RFM69W/CW!
- #define ENABLE_ATC //comment out this line to disable AUTO TRANSMISSION CONTROL
- #define SERIAL_BAUD 115200
- #if defined (MOTEINO_M0) && defined(SERIAL_PORT_USBVIRTUAL)
- #define Serial SERIAL_PORT_USBVIRTUAL // Required for Serial on Zero based boards
- #endif
- #ifdef ENABLE_ATC
- RFM69_ATC radio;
- #else
- RFM69 radio;
- #endif
- bool promiscuousMode = false;
- byte ackCount = 0;
- uint32_t packetCount = 0;
- unsigned long currentMillis;
- unsigned long node1_last, node2_last, node3_last;
- unsigned long node_periode = 1500;
- String notif[3];
- int urutan = 0;
- void(* reset)(void) = 0;
- void setup() {
- pinMode (10, OUTPUT);
- digitalWrite (10, LOW);
- Serial.begin(SERIAL_BAUD);
- delay(10);
- radio.initialize(FREQUENCY,NODEID,NETWORKID);
- #ifdef IS_RFM69HW_HCW
- radio.setHighPower(); //must include this only for RFM69HW/HCW!
- #endif
- radio.encrypt(ENCRYPTKEY);
- radio.promiscuous(promiscuousMode);
- pinMode(8, OUTPUT);
- char buff[50];
- }
- void draw(void) {
- String forshow = "";
- for(int i = 0; i < urutan; i++){
- forshow += notif[i];
- forshow += " ";
- }
- u8g.setFont(u8g_font_unifont);
- u8g.drawStr( 0, 10, "Syauqi TA 2019");
- u8g.drawStr( 0, 30, forshow.c_str());
- }
- void updateNotif(String node, int state){
- if(state == 1){
- bool allow = true;
- for(int i = 0; i < urutan; i++){
- if(notif[i].equals(node)){
- allow = false;
- }
- }
- if(allow){
- if(urutan < 3){
- notif[urutan] = node;
- urutan++;
- }
- }
- }
- else if(state == 0){
- bool allow = false;
- for(int i = 0; i < urutan; i++){
- if(notif[i].equals(node)){
- allow = true;
- }
- }
- if(allow){
- if(urutan > 0){
- int found = 0;
- for(int i = 0; i < urutan; i++){
- if(notif[i].equals(node)){
- found = i;
- }
- break;
- }
- notif[found] = "";
- String temp[3];
- int tambah = 0;
- for(int j = 0; j < urutan; j++){
- if(!notif[j].equals("")){
- temp[tambah] = notif[j];
- tambah++;
- }
- }
- for(int k = 0; k < tambah; k++){
- notif[k] = temp[k];
- }
- urutan--;
- }
- }
- }
- }
- void showNotif(){
- for(int i = 0; i < urutan; i++){
- Serial.print(notif[i]);
- Serial.print(" ");
- }
- Serial.println("");
- }
- void loop() {
- currentMillis = millis();
- if((currentMillis - node1_last) >= node_periode){
- updateNotif("A",1);
- digitalWrite (10, HIGH);
- }
- else{
- updateNotif("A",0);
- digitalWrite (10, LOW);
- }
- if((currentMillis - node2_last) >= node_periode){
- updateNotif("B",1);
- digitalWrite (10, HIGH);
- }
- else{
- updateNotif("B",0);
- digitalWrite (10, LOW);
- }
- if((currentMillis - node3_last) >= node_periode){
- updateNotif("C",1);
- digitalWrite (10, HIGH);
- }
- else{
- updateNotif("C",0);
- digitalWrite (10, LOW);
- }
- u8g.firstPage();
- do {
- draw();
- } while( u8g.nextPage() );
- if (radio.receiveDone())
- {
- Serial.print(++packetCount);
- Serial.print(" Node:[");
- Serial.print(radio.SENDERID, DEC);
- Serial.println("] ");
- int node_id = radio.SENDERID;
- switch(node_id){
- case 2:
- node1_last = currentMillis;
- break;
- case 3:
- node2_last = currentMillis;
- break;
- case 4:
- node3_last = currentMillis;
- break;
- }
- for (byte i = 0; i < radio.DATALEN; i++)
- Serial.print((char)radio.DATA[i]);
- Serial.print(" [RSSI:");Serial.print(radio.RSSI);Serial.print("]");
- Serial.println();
- Blink(LED_BUILTIN,3);
- }
- }
- void Blink(byte PIN, int DELAY_MS)
- {
- pinMode(PIN, OUTPUT);
- digitalWrite(PIN,HIGH);
- delay(DELAY_MS);
- digitalWrite(PIN,LOW);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement