Здравствуйте я уроки (уроки Джереми Блюма) все просмотрел теперь учусь по примерам. Так вот скажите что означает этот скетч? /* * EEPROM Clear * * Sets all of the bytes of the EEPROM to 0. * This example code is in the public domain. */ #include <EEPROM.h> void setup() { // write a 0 to all 512 bytes of the EEPROM for (int i = 0; i < 512; i++) EEPROM.write(i, 0); // turn the LED on when we're done digitalWrite(13, HIGH); } void loop() { }
И этот /* * EEPROM Write * * Stores values read from analog input 0 into the EEPROM. * These values will stay in the EEPROM when the board is * turned off and may be retrieved later by another sketch. */ #include <EEPROM.h> // the current address in the EEPROM (i.e. which byte // we're going to write to next) int addr = 0; void setup() { } void loop() { // need to divide by 4 because analog inputs range from // 0 to 1023 and each byte of the EEPROM can only hold a // value from 0 to 255. int val = analogRead(0) / 4; // write the value to the appropriate byte of the EEPROM. // these values will remain there when the board is // turned off. EEPROM.write(addr, val); // advance to the next address. there are 512 bytes in // the EEPROM, so go back to 0 when we hit 512. addr = addr + 1; if (addr == 512) addr = 0; delay(100); } И этот /* * EEPROM Read * * Reads the value of each byte of the EEPROM and prints it * to the computer. * This example code is in the public domain. */ #include <EEPROM.h> // start reading from the first byte (address 0) of the EEPROM int address = 0; byte value; void setup() { // initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } } void loop() { // read a byte from the current address of the EEPROM value = EEPROM.read(address); Serial.print(address); Serial.print("\t"); Serial.print(value, DEC); Serial.println(); // advance to the next address of the EEPROM address = address + 1; // there are only 512 bytes of EEPROM, from 0 to 511, so if we're // on address 512, wrap around to address 0 if (address == 512) address = 0; delay(500);
Записывает во все ячейки еепрома 0 и сжигает встроенный светодиод Второй записывает в еепром данные с анал. Входа. Третий выводит из еепрома в сериал. Читайте комменты
Второй заполняет еепром по кругу данными Третий выводит из еепрлма в сериал. Все в коментариях написано...
Здравствуйте форумчане. Обращаюсь к вам т.к. не силен в программировании, но появилась нужда в создании RFID системы. Аппаратно все работает, скачал скетч в интернете, залил все заработало как нужно. Мне очень нужна ваша помощь в подробном комментировании кода. Вот так он выглядит: #include <SoftwareSerial.h> SoftwareSerial RFID(2, 3); // RX and TX int data1 = 0; int ok = -1; int yes = 13; int no = 12; int tag1[14] = {2,55,49,48,48,56,54,53,70,70,48,53,56,3}; int newtag[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0}; void setup() { RFID.begin(9600); Serial.begin(9600); pinMode(yes, OUTPUT); pinMode(no, OUTPUT); } boolean comparetag(int aa[14], int bb[14]) { boolean ff = false; int fg = 0; for (int cc = 0 ; cc < 14 ; cc++) { if (aa[cc] == bb[cc]) { fg++; } } if (fg == 14) { ff = true; } return ff; } void checkmytags() { ok = 0; if (comparetag(newtag, tag1) == true) { ok++; ok++; } } void readTags() { ok = -1; if (RFID.available() > 0) { delay(100); for (int z = 0 ; z < 14 ; z++) { data1 = RFID.read(); newtag[z] = data1; } RFID.flush(); checkmytags(); } if (ok > 0) { Serial.println("Yes"); digitalWrite(yes, HIGH); delay(1000); digitalWrite(yes, LOW); ok = -1; } else if (ok == 0) { Serial.println("NO!!!"); digitalWrite(no, HIGH); delay(1000); digitalWrite(no, LOW); ok = -1; } } void loop() { readTags(); } Заранее спасибо, очень благодарен за ответ.
Код (Text): #include <SoftwareSerial.h> //активируем библиотеку, в которой описаны функции SoftwareSerial RFID(2, 3); // RX и TX выводы, отвечают за отправку и прием данных по Serial (то, что вы с компа в СОМ порт шлете и принимаете) //Переменные для работы int data1 = 0; int ok = -1; int yes = 13; int no = 12; //Массивы данных: int tag1[14] = {2,55,49,48,48,56,54,53,70,70,48,53,56,3}; //Это массив для хранения ID вашей метки или карты int newtag[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0}; void setup() { RFID.begin(9600); //Устанавливаем скорость чтения/записи, 9600 бод Serial.begin(9600); //Устанавливаем скорость чтения/записи, 9600 бод pinMode(yes, OUTPUT); //Устанавливаем режим пина - OUTPUT(выход) или INPUT (вход) pinMode(no, OUTPUT); //-*- } boolean comparetag(int aa[14], int bb[14]) //Создаем функцию для "сравнивания меток" { //Возвращает "true" если удачная проверка, или "false" при неудаче. boolean ff = false; int fg = 0; for (int cc = 0 ; cc < 14 ; cc++) { if (aa[cc] == bb[cc]) { fg++; } } if (fg == 14) { ff = true; } return ff; } void checkmytags() //Проверка "моей" метки/карты { ok = 0; if (comparetag(newtag, tag1) == true) { ok++; ok++; } } void readTags() //Функция чтения карт/меток { ok = -1; if (RFID.available() > 0) { delay(100); for (int z = 0 ; z < 14 ; z++) { data1 = RFID.read(); newtag[z] = data1; } RFID.flush(); checkmytags(); } if (ok > 0) //Если считали, пишем в СОМ-порт "Yes" { Serial.println("Yes"); digitalWrite(yes, HIGH); delay(1000); digitalWrite(yes, LOW); ok = -1; } else if (ok == 0) //иначе "NO!!!" { Serial.println("NO!!!"); digitalWrite(no, HIGH); delay(1000); digitalWrite(no, LOW); ok = -1; } } void loop() //Начало программы, бесконечно читаем карты, пока девайс не выключат. { readTags(); } Вот немного пояснил, не являюсь владельцем "считывателя" RFID, некоторые части не пояснил
Дружище спасибо большое. А не подскажешь, что именно означает "аа' "bb" "cc" они откуда взялись? или то они означают ?
int aa[14], int bb[14], int cc = 0 - это все переменные. Когда вы создаете функцию, вы можете использовать любые имена переменных, главное - это их тип. Почитайте лучше в интернете "Как создать свою функцию", посмотрите видеоуроки. Я не смогу вам внятно пояснить что это. Скажу только, что они используются только для описания функции, в коде вы их не встретите.