Arduino with RFM69HW control 2 leds code
Arduino with RFM69HW control 2 leds code More
This is some Code examples
Arduino with RFM69HW control 2 leds code More
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
/* By Roee Bloch Livolo Automatic Smart home turn on/off lights between definded hours! #define lock_time 30 // if it gets to 30 seconds it will shut off/on the light #define start_time 20 // it will start operation at 8:00 oclock evening #define stop_time 23 // till eleven oclock looks good to me All right Reserved Copyright (c) 2015 All Right Reserved, http://www.electronics-freak.com This source is subject to the Roee Bloch License. Please see the License.txt file for more information. All other rights reserved. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. </copyright> <author>Roee Bloch</author> <email>roeebloch@walla.co.il</email> <date>August 2015</date> Wifly automatic home control - using Telnet anywhere with home router address The commands are c1 activate GPIO4 to '1' c0 deactive GPIO4 to '0' c2 unlocked for 3 minuets without feedback after locked rr read status of gpio4 r0 reset internal counter to zero //PINS in USE are: //D4 - relay command //A4 - RTC DATA //A5 - RTC CLK //D6 - Reset pin to Wifly (to Wifly pin 5) //D10 - RX WIFLY (TX) //D11 - TX WIFLY (RX) // //need to connect resistor in series to change from 5V to 3.3V //suggest 1K, 2.2K while 2.2K to GND and 1K to D10,D11 // // // // using timer library from NET //https://github.com/JChristensen/Timer //to add it goto Sketch-> import library -> add librarry -> choose the ZIP file // //april 2015 - adding I2C RTC //on NANO A4=DATA, A5=CLK //another library for RTC: //RTC DS1307RTC */ #include <Wire.h> #include <Time.h> #include <DS1307RTC.h> #include <livolo.h> #define SIGNAL_IN 0 // INTERRUPT 0 = DIGITAL PIN 2 - use the interrupt number in attachInterrupt #define lock_time 30 // if it gets to 30 seconds it will shut off/on the light #define start_time 20 // it will start operation at 8:00 oclock evening #define stop_time 23 // till eleven oclock looks good to me volatile byte impulse = 0; // kolejny puls volatile int bufor[53]; volatile boolean header = false; volatile unsigned long StartPeriod = 0; // set in the interrupt volatile boolean stop_ints = false; Livolo livolo(8); // transmitter connected to pin #8 unsigned char mytime, myhours; char rxtx = 0; // reading digital pin 3 if zero will be ceceiver if 1 transmitter int my_lock_time = lock_time; // convert it to INT this is how it works int my_start_time = start_time; // convert it to INT this is how it works int my_stop_time = stop_time; // convert it to INT this is how it works char one_transmission_flag = 0; void setup() { Serial.begin(9600); pinMode(3, INPUT); pinMode(13, OUTPUT); // on board LED attachInterrupt(SIGNAL_IN, calcInput, CHANGE); while (!Serial) ; // wait for serial delay(200); Serial.println("DS1307RTC Read Test"); Serial.println("-------------------"); livolo.sendButton(2011, 106); // all lights off code } void loop() { tmElements_t tm; if (RTC.read(tm)) { Serial.print("Ok, Time = "); print2digits(tm.Hour); Serial.write(':'); print2digits(tm.Minute); Serial.write(':'); print2digits(tm.Second); Serial.print(", Date (D/M/Y) = "); Serial.print(tm.Day); Serial.write('/'); Serial.print(tm.Month); Serial.write('/'); Serial.print(tmYearToCalendar(tm.Year)); Serial.println(); mytime = tm.Second; myhours = (tm.Hour); Serial.println(mytime); Serial.print("hours is:"); Serial.println(myhours); if ((myhours > my_start_time - 1) && (myhours < my_stop_time)) { Serial.println("Working ......"); one_transmission_flag = 0; if ((mytime == my_lock_time) || ((mytime + 1) == my_lock_time)) { tx_onoff_light(random(3)); // pick random light } } else { if (one_transmission_flag == 0) { Serial.println("transmitting OFF"); one_transmission_flag = 1; livolo.sendButton(2011, 106); // all lights off code } } } else { if (RTC.chipPresent()) { Serial.println("The DS1307 is stopped. Please run the SetTime"); Serial.println("example to initialize the time and begin running."); Serial.println(); } else { Serial.println("DS1307 read error! Please check the circuitry."); Serial.println(); } delay(9000); } delay(1000); } void print2digits(int number) { if (number >= 0 && number < 10) { Serial.write('0'); } Serial.print(number); } void calcInput() { // get the time using micros unsigned int duration = (int)(micros() - StartPeriod); // save pulse length to bufor StartPeriod = micros(); //begin next impulse //Serial.println(StartPeriod); if (stop_ints) return; if ((duration < 90) || (duration > 600)) goto reset; //impulse not right bufor[impulse++] = duration; if (duration < 415) return; if (!header) { header = true; impulse = 0; return; } else { if ((impulse < 23) || (impulse > 52)) goto reset; //too long or too short info stop_ints = true; return; } reset: header = false; impulse = 0; return; } void txrx_blink(char param) { int mydelay; char myloop; if (param == 0) // Receiver { mydelay = 500; myloop = 2; } else { mydelay = 100; myloop = 3; } for (int i = 0; i < myloop; i++) { digitalWrite(13, 1); delay(mydelay); digitalWrite(13, 0); delay(mydelay); } } void receiver() { while (1) { if (stop_ints) //data in buffer { unsigned long binary = 1; //byte i = 0; for (byte j = 0; j < 46; j++) { //Serial.print(binary); if ((bufor[j] > 220) && (bufor[j] < 400)) { binary <<= 1; //binary |= 1; //i++; bitSet(binary, 0); } else if ((bufor[j] > 90) && (bufor[j] < 220) && (bufor[j + 1] > 90) && (bufor[j + 1] < 220)) { binary <<= 1; j++; } else if ((bufor[j] > 90) && (bufor[j] < 220) && (bufor[j + 1] > 220) && (bufor[j + 1] < 400)) { binary <<= 1; bitSet(binary, 0); //i += 2; j++; } else break; } //Serial.println(bitRead(binary,4)); if (bitRead(binary, 23)) { bitClear(binary, 23); Serial.print("remoteID:"); Serial.print((binary / 128) & 65535); Serial.print(" - "); Serial.print("key code:"); Serial.println(binary & 127); } else { Serial.println("wrong code "); Serial.println(binary, BIN); } delay (1000); txrx_blink(1); header = false; impulse = 0; stop_ints = false; // } } } } void transmit() // not in use this is part of other program { while (1) { // livolo.sendButton(6400, 120); // blink button #3 every 3 seconds using remote with remoteID #6400 txrx_blink(0); delay(2000); Serial.println("Transmitting key 1 NOW..."); livolo.sendButton(2011, 0); // my key 1 txrx_blink(0); delay(2000); Serial.println("Transmitting key 2 NOW..."); livolo.sendButton(2011, 96); // my key 2 txrx_blink(0); delay(2000); Serial.println("Transmitting key 3 NOW..."); livolo.sendButton(2011, 120); // my key 3 } } void tx_onoff_light(int x) // switch on/off button by value every number is different light { Serial.print("Transmitting now on/off...."); Serial.println(x); switch (x) { case 1: livolo.sendButton(2011, 0); // my key 1 break; case 2: livolo.sendButton(2011, 96); // my key 2 break; case 3: livolo.sendButton(2011, 120); // my key 3 break; } } |
This Program is doing automatic on/off randomly, all you have to do is set the number of switch that you have and the time limits (start time and stop time) – between those times, it will automatically control the lights. This uses the following: Arduino Uno board RTC DS1307 board – real time […] More
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
/* By Roee Bloch Fish feeder improved All right Reserved Copyright (c) 2015 All Right Reserved, http://www.electronics-freak.com This source is subject to the Roee Bloch License. Please see the License.txt file for more information. All other rights reserved. THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. </copyright> <author>Roee Bloch</author> <email>roeebloch@walla.co.il</email> <date>August 2015</date> also took servo from here: Controlling a servo position using a potentiometer (variable resistor) by Michal Rinott <http://people.interaction-ivrea.it/m.rinott> modified on 8 Nov 2013 by Scott Fitzgerald http://www.arduino.cc/en/Tutorial/Knob */ #include <Servo.h> #include <EEPROM.h> Servo myservo; // create servo object to control a servo int potpin = 0; // analog pin used to connect the potentiometer int val; // variable to read the value from the analog pin int time1, time2; // time int data, degree1; int first_run = 0; int minutes, hours; void setup() { degree1 = EEPROM.read(0); // reading address 0 myservo.attach(9); // attaches the servo on pin 9 to the servo object delay(50); myservo.write(degree1); Serial.begin(9600); time1 = millis(); // Serial.println(time1); } void loop() { if (first_run == 0) { // waiting for reset command 30 seconds Serial.println("waiting for Servo reset command to ZERO degrees, hours and minutes, press 'r' and ENTER to RESET"); time2 = millis(); while ((time2 - time1) < 10000) // we are in first 30 seconds waiting for commands { data = Serial.read(); if (Serial.available() > 0) { // read the incoming byte: data = Serial.read(); // say what you got: Serial.print("I received: "); Serial.println(data, DEC); if (data == 114) { Serial.println("Reset to Zero degrees now and eeprom"); EEPROM.write(0, 0); // wiriting address 0 value 0 // not in use now EEPROM.write(1, 0); // reseting hours EEPROM.write(2, 0); // reseting minutes } Serial.flush(); } time2 = millis(); } Serial.println("Time passed - code continue"); first_run = 1; } hours = EEPROM.read(1); // reading hours minutes = EEPROM.read(2); // reading hours Serial.println("hours that passed"); Serial.println(hours); Serial.println("minutes that passed"); Serial.println(minutes); if (hours == 23) { Serial.println("Reseting hours to ZERO"); hours = 0; } if (minutes == 59) { Serial.println("Reseting minutes to ZERO"); minutes = 0; } while(1) // never ending loop { wait_day(); for (int x=0; x<4;x++) { myservo.write(0); // sets the servo position to 0 delay(1000); myservo.write(180); delay(1000); myservo.write(0); delay(1000); } } } void wait_day() { for (int y = hours; y < 24; y++) //counting 24 hours { EEPROM.write(1, y); // saving hours for (int x = minutes; x < 60; x++) //minutes delay { EEPROM.write(2, x); // saving hours delay(60000); // delay(15); //for debug } } Serial.println("day passed!"); //reseting hours and minutes now hours = 0; minutes = 0; } |
This code uses Servo motor, and just 2 holes in circular plastic box Every 24 hours that box will rotate 4 times throwing food out of holes if there was electricity power off – when the power on again it will continue from last time Since it saves hours and minutes to ARDUINO memory […] More
Arduino Remote Controlled Car Code More
Lesson 14 Arduino Capacitor Meter Code More
Lesson 13 Resistor Meter code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
// By Roee Bloch Resistor-Meter //All right Reserved // Copyright (c) 2015 All Right Reserved, http://www.electronics-freak.com // // This source is subject to the Roee Bloch License. // Please see the License.txt file for more information. // All other rights reserved. // // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // </copyright> // <author>Roee Bloch</author> // <email>roeebloch@walla.co.il</email> // <date>June 2015</date> /* Part of the CODE is LCD Taken from: Library originally added 18 Apr 2008 by David A. Mellis library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net) example added 9 Jul 2009 by Tom Igoe modified 22 Nov 2010 by Tom Igoe Formulas in use are: R(measured) = (RKnown(VCC-Vmeasured))/VMeasured V(measured) = ((ADC VALUE)/1024)*VCC */ #include <LiquidCrystal.h> #define analog_in 1 // define analog input pin in use #define VCC 5 //define VCC for calculation #define R_known 46700 // define Reference resistor in use, I have found this value is very good to many measurements, but if you have another resistor you may change this value according float R_measured, V_measured, R_measK ; int analog_read; char flag = 0; // initialize the library with the numbers of the interface pins LiquidCrystal lcd(8, 9, 4, 5, 6, 7); void setup() { Serial.begin(57600); Serial.println("Starting"); lcd.begin(16, 2); lcd.print("Resistor Meter"); } void loop() { analog_read = analogRead(analog_in); while (analog_read == 0) { if (0 == flag) { Serial.println("Please connect resistor"); lcd.setCursor(0, 1); lcd.print("Connect Resistor"); flag = 1; } analog_read = analogRead(analog_in); } flag = 0; // this is in order to print message connect resistor once only! V_measured = (analog_read) * VCC; // this is voltage *1024 since we did not divide by 1024 V_measured = V_measured / 1024.0; R_measured = (R_known * (VCC - V_measured)) / V_measured; if (R_measured <= 1000) { Serial.print("Resistor is:"); Serial.print(R_measured); Serial.println(" ohms"); myclear(); lcd.setCursor(0, 1); lcd.print("R="); lcd.print(R_measured); lcd.print(" ohms"); } if (R_measured > 1000) { Serial.print("Resistor is:"); R_measK = R_measured / 1000; Serial.print((R_measK)); Serial.println(" K ohms"); myclear(); lcd.setCursor(0, 1); lcd.print("R="); lcd.print(R_measK); lcd.print(" K ohms"); } delay(1000); } void myprint(float x, String param) { int myprint; myprint = (x); Serial.print(param); Serial.print(" is:"); Serial.println(myprint); } void myclear() // clear all second line { lcd.setCursor(0, 1); lcd.print(" "); } |
Lesson 12 – Logic Gates code In this Lesson I will teach about LOGIC Gates, with a very FUN and Simple Program. The Program will Light LEDS and Print On Screen According to LOGIC GATES: AND, OR, NOT, NAND (other will be covered in Next lessons) More
This is the Code of Christmas Tree
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 |
// By Roee Bloch CHRISTMAS TREE //All right Reserved // Copyright (c) 2015 All Right Reserved, http://www.electronics-freak.com // // This source is subject to the Roee Bloch License. // Please see the License.txt file for more information. // All other rights reserved. // // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // </copyright> // <author>Roee Bloch</author> // <email>roeebloch@walla.co.il</email> // <date>June 2015</date> #define strips 5 // number of strip lamps to be used #define mydelay 400 // delay of 1000 ms between changes #define randompin 12 // when this digital pin conneted to GND will run RANDOM PATTERNS int myrandom, mode = 1; // if mode=0 => random mode 1 is normal byte cal = 1,my_top; int num, func_num = 0,top,random_delay; byte mypins[] = {2, 3, 4, 5, 6, 7, 8, 9}; //maximum 8 outputs for this program from LSB to MSB void setup() { pinMode(randompin, INPUT); // set pin to input digitalWrite(randompin, HIGH); // turn on pullup resistors Serial.begin(9600); if ((strips <= 8) && (strips > 1)) // check if number of Relays is between 2 and 8 { for (int x = 0; x < strips; x++) // decalre all RELAYS as OUTPUTS in one loop { // Serial.print("IO="); // Serial.println(int(mypins[x])); pinMode (mypins[x], OUTPUT); } } Serial.println("started"); pinMode (2, OUTPUT); top = pow(2, strips)-1; // max number for chosen strips my_top=byte(top); // for mask } void loop() { digitalWrite(randompin, HIGH); if (digitalRead(randompin) == 0) //random mode { Serial.println("Random mode"); mode = 0; func_num = random(1, 9); // random run random_delay= random(1,11)*100; Serial.print("Random delay is:"); Serial.println(random_delay); } else { Serial.println("Regular mode"); mode = 1; func_num++; // go pattern one by one 1,2,3,.... random_delay=mydelay; } Serial.println(func_num); switch (func_num) { case 1: pattern1(); break; case 2: pattern2(); break; case 3: pattern3(); break; case 4: pattern4(); break; case 5: pattern5(); break; case 6: pattern6(); break; case 7: pattern7(); break; case 8: func_num = 0; cal = 1; break; } } void LightLeds(byte x) { int mystart; String myNumber = String(x, BIN); // convert byte to string in order to work with it easily int binLength = myNumber.length(); if (binLength < 8) { digitalWrite(mypins[binLength], 0); } for (int q = binLength, mystart = 0; q > 0; q--, mystart++) { if (myNumber[q - 1] == '1') { digitalWrite(mypins[mystart], 1); // need to get to correct bit } else { digitalWrite(mypins[mystart], 0); // need to get to correct bit } } } void pattern1() // move left { cal=1; for (int a = 1; a <= strips; a++) { LightLeds(cal); delay(random_delay); cal = cal * 2; } cal = 1; all_off(); } void pattern2() // move right { cal = pow(2, strips); for (int a = strips; a >= 0; a--) { delay(random_delay); cal = cal >> 1; LightLeds(cal); } all_off(); } void mystop() { Serial.println("stopped"); loop2: goto loop2; } void all_off() { for (int i = 0; i < 8; i++) { digitalWrite(mypins[i], 0); } } void pattern3() //binary up { cal = 1; byte limit; limit=my_top+1; // int top = pow(2, strips); // my_top=byte(top); // for mask for (int i = 1; i <=limit; i++) { delay(random_delay); cal = i; LightLeds(cal); } } void pattern4() //blink half half { for (int i = 1; i < 6; i++) { delay(random_delay); LightLeds(170 & my_top); // equal to 10101010 delay(random_delay); LightLeds(85 & my_top);// equal to 1010101 } all_off(); } void pattern5() // blink all together { for (int i = 1; i < 6; i++) { delay(random_delay); LightLeds(my_top); delay(random_delay); all_off(); } } void pattern6() { for (int i = 1; i < 6; i++) // two and two { delay(random_delay); LightLeds(204 & my_top); delay(random_delay); LightLeds(51 & my_top); } all_off(); } void pattern7() //binary down { cal = 1; for (int i = my_top; i >= 0; i--) { delay(random_delay); cal = i; LightLeds(i); } all_off(); } |
Video for Theory: lesson-11-christmas-tree-part-1 Video of First Run: lesson-11-christmas-tree-lights-part-2 Video with Strong Leds: lesson-11-christmas-tree-lights-part-3 More
Here is Arduino Motor PWM code More
Lesson 10 Timer Code Example More
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
// By Roee Bloch //All right Reserved // Copyright (c) 2015 All Right Reserved, http://www.electronics-freak.com // // This source is subject to the Roee Bloch License. // Please see the License.txt file for more information. // All other rights reserved. // // THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY // KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A // PARTICULAR PURPOSE. // // // Roee Bloch // roeebloch@walla.co.il // June 2015 #define octave 2 // Octav to hear Lower tones leave value 1 #define Buz1 5 // buzzer pin 1 #define Buz2 7 // buzzer pin 2 #define DO 2500/octave //cycle time of DO in Micro seconds of musical notes #define RE 2028/octave #define MI 1805/octave #define FA 1702/octave #define SOL 1516/octave #define LA 1351/octave #define SI 1204/octave #define analog_in 0 int my_analog; int remap; void setup() { // put your setup code here, to run once: pinMode(Buz1, OUTPUT); pinMode(Buz2, OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: my_analog = analogRead(analog_in); Serial.println (my_analog); //for debug only remap = map (my_analog, 0, 1024, 0, 8); // remapping to switch case // Serial.println (remap); // also for debug switch (remap) { case 1: Serial.println ("DO"); sound(DO); break; case 2: Serial.println ("RE"); sound(RE); break; case 3: Serial.println ("MI"); sound(MI); break; case 4: Serial.println ("FA"); sound(FA); break; case 5: Serial.println ("SOL"); sound(SOL); break; case 6: Serial.println ("LA"); sound(LA); break; case 7: Serial.println ("SI"); sound(SI); break; } delay(5); } void sound(int mydelay) //mydelay is the actual frequency according to musical note { for (int q = 1; q < 100; q++) { digitalWrite(Buz1, 1); digitalWrite(Buz2, 0); delayMicroseconds(mydelay / 2); digitalWrite(Buz1, 0); digitalWrite(Buz2, 1); delayMicroseconds(mydelay / 2); } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
This is the Code of Receiver and Transmitter RF (NANO transmit, UNO Receive) < !--more-- > //This is the Code of Receiver and Transmitter RF (NANO transmit, UNO Receive) //Arduino NANO transmitter side //----------------------------------------------------------------------// // Pin 13 has an LED connected on most Arduino boards. int led = 13; int num = 0; String comdata = ""; void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); Serial.begin(9600); Serial.println("Hello, I am Arduino"); Serial.println("HI number 1"); } //Serial data transceiver void loop() { delay(1000); Serial.print("HI number "); Serial.println(num++); while (Serial.available() > 0) { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) comdata += char(Serial.read()); delay(2); } if (comdata.length() > 0) { Serial.println(comdata); comdata = ""; } digitalWrite(led, LOW); // turn the LED off by making the voltage LOW } _____________________________________________________________________________________________________________ //UNO Receiver Side //----------------------------------------------------------------------// // Pin 13 has an LED connected on most Arduino boards. int led = 13; #include String readString; SoftwareSerial mySerial(10, 11); // RX, TX void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); Serial.begin(9600); //computer PORT mySerial.begin(9600); // RF PORT //Serial.println("Hello, I am Arduino"); } //Serial data transceiver void loop() { while (mySerial.available()) { delay(3); //delay to allow byte to arrive in input buffer char c = mySerial.read(); readString += c; } if (readString.length() > 0) { Serial.println(readString); readString = ""; } //digitalWrite(led, LOW); // turn the LED off by making the voltage LOW } < / code > |
Enter your account data and we will send you a link to reset your password.
To use social login you have to agree with the storage and handling of your data by this website.
AcceptHere you'll find all collections you've created before.