Дополнительные ссылки:
Кнопки
// the loop function runs over and over again forever void loop() { if (digitalRead(ButtonPin) == LOW) { digitalWrite(LEDPin, HIGH); // turn the LED on (HIGH is the voltage level) } else { digitalWrite(LEDPin, LOW); // turn the LED off by making the voltage LOW } }
Дребезг контактов
Подавления дребезга механических контактов с использованием программных библиотек Bounce
Ecco lo sketch: // Sirena della Polizia int wait= 1; int time =10; int freq = 0; int ledPin1 =2; int ledPin2 =3; int tonePin =8; void setup(){ pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); } void loop() { for (freq = 160; freq < 1700; freq += 1) { // valore iniziale, valore limite high, incremento tone(tonePin, freq, time); // Pin del piezo, frequenza, durata digitalWrite(ledPin1,LOW); digitalWrite(ledPin2,HIGH); delay(wait); } for (freq = 1700; freq > 160; freq -= 1) {// valore iniziale, valore limite low, decremento tone(tonePin, freq, time); digitalWrite(ledPin1,HIGH); digitalWrite(ledPin2,LOW); delay(wait); } }
Замена delay() для неблокирующих задержек в Arduino IDE
Для изучения основ работы с платой Arduino можно использовать готовые наборы, содержащие не только необходимые электронные компоненты для проведения учебных экспериментов, но и сопроводительную брошюру с описанием учебных проектов, с исходным программным кодом, с электронными схемами киберфизических устройств.
Наборы, которые удобно использовать в учебном процессе:
Затрудняюсь отдать предпочтение какому либо из данных наборов, в каждом есть свои преимущества и свои недостатки. Для организации занятий в кружке элементов набора недостаточно, постоянно приходится пополнять список деталей, необходимых для учебных экспериментов…
https://www.electronshik.ru/item/kit-mp3117box-2564174
/* LiquidCrystal Library - scrollDisplayLeft() and scrollDisplayRight() Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD displays that are compatible with the Hitachi HD44780 driver. There are many of them out there, and you can usually tell them by the 16-pin interface. This sketch prints "Hello World!" to the LCD and uses the scrollDisplayLeft() and scrollDisplayRight() methods to scroll the text. The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * LCD R/W pin to ground * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) 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 This example code is in the public domain. http://www.arduino.cc/en/Tutorial/LiquidCrystalScroll */ // include the library code: //#include <LineDriver.h> #include <LiquidCrystal.h> //#include <LiquidCrystalRus.h> //byte bukva_F[8] = {B00100,B11111,B10101,B10101,B11111,B00100,B00100,B00000,}; // Буква "Ф" // initialize the library with the numbers of the interface pins LiquidCrystal lcd(13, 12, 11, 10, 9, 8); void setup() { // set up the LCD's number of columns and rows: lcd.begin(16, 2); // lcd.createChar(9, bukva_F); // Print a message to the LCD. lcd.setCursor(0,0); lcd.print("HOBA\xB1 \xA5H\xAAOPMAT\xA5KA! \xA8""EPE""\xA4""A""\xA1P\xA9\xA4KA!"); //lcd.print("\xE0\xE1\xE2\xE3\xE4\xE5\xE6"); //lcd.print("\xA0\xA1\xA2\xA3\xA4\xA5\xA6"); //lcd.print("\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF\xB0"); //lcd.print(" \xA8 p \xB8 \xB3 e \xBF"); //lcd.print("xC0\xC1\xC2\xC3\xC4\xC5\xC6\xC7\xC8\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xD9\xDA\xDB\xDC\xDD\xDE\xDF\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF1\xF2\xF3\xF4\xF5\xF6\xF7\xF8\xF9\xFA\xFB\xFC\xFD\xFE\xFF/\xE1\xE2\xF7\xE7\xE4\xE5\xF6\xFA\xE9\xEA\xEB\xEC\xED\xEE\xEF\xF0\xF2\xF3\xF4\xF5\xE6\xE8\xE3\xFE\xFB\xFD\xFF\xF9\xF8\xFC\xE0\xF1\xC1\xC2\xD7\xC7\xC4\xC5\xD6\xDA\xC9\xCA\xCB\xCC\xCD\xCE\xCF\xD0\xD2\xD3\xD4\xD5\xC6\xC8\xC3\xDE\xDB\xDD\xDF\xD9\xD8\xDC\xC0\xD1"); delay(1000); } void loop() { // scroll 13 positions (string length) to the left // to move it offscreen left: for (int positionCounter = 0; positionCounter < 30; positionCounter++) { // scroll one position left: lcd.scrollDisplayLeft(); // wait a bit: delay(300); } /* // scroll 29 positions (string length + display length) to the right // to move it offscreen right: for (int positionCounter = 0; positionCounter < 34; positionCounter++) { // scroll one position right: lcd.scrollDisplayRight(); // wait a bit: delay(300); } // scroll 16 positions (display length + string length) to the left // to move it back to center: for (int positionCounter = 0; positionCounter < 16; positionCounter++) { // scroll one position left: lcd.scrollDisplayLeft(); // wait a bit: delay(300); } // delay at the end of the full loop: delay(300); */ }