acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
AFSK_Imperial_March.ino (2646B)
1 /* 2 RadioLib AFSK Imperial March Example 3 4 This example shows how to EXECUTE ORDER 66 5 6 Other modules that can be used for AFSK: 7 - SX127x/RFM9x 8 - RF69 9 - SX1231 10 - CC1101 11 - Si443x/RFM2x 12 13 For default module settings, see the wiki page 14 https://github.com/jgromes/RadioLib/wiki/Default-configuration 15 16 For full API reference, see the GitHub Pages 17 https://jgromes.github.io/RadioLib/ 18 */ 19 20 // include the library 21 #include <RadioLib.h> 22 23 // include the melody 24 #include "melody.h" 25 26 // SX1278 has the following connections: 27 // NSS pin: 10 28 // DIO0 pin: 2 29 // RESET pin: 9 30 // DIO1 pin: 3 31 SX1278 radio = new Module(10, 2, 9, 3); 32 33 // create AFSK client instance using the FSK module 34 // this requires connection to the module direct 35 // input pin, here connected to Arduino pin 5 36 // SX127x/RFM9x: DIO2 37 // RF69: DIO2 38 // SX1231: DIO2 39 // CC1101: GDO2 40 // Si443x/RFM2x: GPIO 41 AFSKClient audio(&radio, 5); 42 43 void setup() { 44 Serial.begin(9600); 45 46 // initialize SX1278 with default settings 47 Serial.print(F("[SX1278] Initializing ... ")); 48 int state = radio.beginFSK(); 49 50 // when using one of the non-LoRa modules for AFSK 51 // (RF69, CC1101,, Si4432 etc.), use the basic begin() method 52 // int state = radio.begin(); 53 54 if(state == RADIOLIB_ERR_NONE) { 55 Serial.println(F("success!")); 56 } else { 57 Serial.print(F("failed, code ")); 58 Serial.println(state); 59 while(true); 60 } 61 62 // initialize AFSK client 63 Serial.print(F("[AFSK] Initializing ... ")); 64 state = audio.begin(); 65 if(state == RADIOLIB_ERR_NONE) { 66 Serial.println(F("success!")); 67 } else { 68 Serial.print(F("failed, code ")); 69 Serial.println(state); 70 while(true); 71 } 72 } 73 74 void loop() { 75 Serial.print(F("[AFSK] Executing Order 66 ... ")); 76 77 // calculate whole note duration 78 int wholenote = (60000 * 4) / 120; 79 80 // iterate over the melody 81 for(unsigned int note = 0; note < sizeof(melody) / sizeof(melody[0]); note += 2) { 82 // calculate the duration of each note 83 int noteDuration = 0; 84 int divider = melody[note + 1]; 85 if(divider > 0) { 86 // regular note, just proceed 87 noteDuration = wholenote / divider; 88 } else if(divider < 0) { 89 // dotted notes are represented with negative durations!! 90 noteDuration = wholenote / abs(divider); 91 noteDuration *= 1.5; // increases the duration in half for dotted notes 92 } 93 94 // we only play the note for 90% of the duration, leaving 10% as a pause 95 audio.tone(melody[note]); 96 delay(noteDuration*0.9); 97 audio.noTone(); 98 delay(noteDuration*0.1); 99 } 100 101 Serial.println(F("done!")); 102 103 // wait for a second 104 delay(1000); 105 }