├── libs ├── Adafruit_GFX │ ├── Adafruit_GFX.cpp │ ├── Adafruit_GFX.h │ ├── README.txt │ ├── glcdfont.c │ └── license.txt ├── Adafruit_ST7735 │ ├── Adafruit_ST7735.cpp │ ├── Adafruit_ST7735.h │ ├── README.txt │ └── examples │ │ ├── graphicstest │ │ └── graphicstest.pde │ │ ├── graphicstest_highspeed │ │ └── graphicstest_highspeed.pde │ │ ├── rotationtest │ │ └── rotationtest.pde │ │ ├── rotationtest_highspeed │ │ └── rotationtest_highspeed.pde │ │ ├── shieldtest │ │ └── shieldtest.pde │ │ ├── spitftbitmap │ │ └── spitftbitmap.pde │ │ └── spitftbitmap_rotate │ │ └── spitftbitmap_rotate.pde ├── SerialFlow │ ├── SerialFlow.cpp │ ├── SerialFlow.h │ └── readme.txt └── digitalWriteFast │ ├── digitalWriteFast.h │ └── keywords.txt └── sketches ├── ADC_lesson ├── adc │ └── adc.ino └── adc_lesson │ └── adc_lesson.ino ├── AS5048a └── AS5048a.ino ├── Baro_Comp_article ├── baro_BMP180_slave │ └── baro_BMP180_slave.ino ├── baro_BMP85_master │ └── baro_BMP85_master.ino └── baro_MS5611_slave │ └── baro_MS5611_slave.ino ├── Buttons_lesson ├── button-simple │ └── button-simple.ino ├── button-trigger │ └── button-trigger.ino ├── buttons │ └── buttons.ino └── buttons_serial_2x │ └── buttons_serial_2x.ino ├── DS3231_lesson └── ds3231 │ └── ds3231.ino ├── Display.LCD1602_lesson ├── ardu-lcd-text-2 │ └── ardu-lcd-text-2.ino └── ardu-lcd-text │ └── ardu-lcd-text.ino ├── Display.NOKIA5110_lesson ├── nokia5110 │ └── nokia5110.ino ├── nokia5110_bender │ └── nokia5110_bender.ino ├── nokia5110_prim │ └── nokia5110_prim.ino ├── nokia5110_smile │ └── nokia5110_smile.ino ├── nokia5110_snake │ ├── Matrix3216.cpp │ ├── Matrix3216.h │ └── nokia5110_snake.ino └── nokia5110_text │ └── nokia5110_text.ino ├── Display.OLED_RGB_article ├── bmp │ └── bmp.ino └── test │ └── test.ino ├── Display.OLED_lesson ├── OLED_game │ └── OLED_game.ino ├── OLED_robotclass │ └── OLED_robotclass.ino ├── OLED_robotclass_uno │ └── OLED_robotclass_uno.ino └── OLED_text │ └── OLED_text.ino ├── EEPROM_lesson ├── eeprom_put_int │ └── eeprom_put_int.ino ├── eeprom_write │ └── eeprom_write.ino └── eeprom_write_int │ └── eeprom_write_int.ino ├── Game.AlienInvaders_lesson ├── RobotClass-game-10-status │ └── RobotClass-game-10-status.ino ├── RobotClass-game-11-states │ └── RobotClass-game-11-states.ino ├── RobotClass-game-9-life │ └── RobotClass-game-9-life.ino ├── RobotClass-game-enemy │ └── RobotClass-game-enemy.ino ├── RobotClass-game-fire │ └── RobotClass-game-fire.ino ├── RobotClass-game-kill │ └── RobotClass-game-kill.ino ├── RobotClass-game-movements │ └── RobotClass-game-movements.ino ├── RobotClass-game-player │ └── RobotClass-game-player.ino ├── RobotClass-game-points │ └── RobotClass-game-points.ino └── RobotClass-game-sprite │ └── RobotClass-game-sprite.ino ├── IOT.ESP32_MQTT_lesson ├── mqtt_publish │ └── mqtt_publish.ino └── mqtt_publish_number │ └── mqtt_publish_number.ino ├── IOT.ESP_MQTT_lesson ├── mqtt │ └── mqtt.ino └── mqtt_publish │ └── mqtt_publish.ino ├── IOT.Matrix_8x8_article └── nodemcu-matrix │ └── nodemcu-matrix.ino ├── Interrupt_lesson ├── ardu-irq-rpm │ └── ardu-irq-rpm.ino └── ardu-irq-serial │ └── ardu-irq-serial.ino ├── LED.7segment_595_lesson ├── seg_led_reg │ └── seg_led_reg.ino └── seg_led_reg_digits │ └── seg_led_reg_digits.ino ├── LED.Basic_lesson ├── Blink-svetofor │ └── Blink-svetofor.ino ├── Blink │ └── Blink.ino └── heartbeat │ └── heartbeat.ino ├── LED.Dynamic_lesson ├── dyn_3digit │ └── dyn_3digit.ino └── dyn_3digit_static │ └── dyn_3digit_static.ino ├── LED.Led_Matrix_595_lesson ├── led-matrix-8x8-max7219-char │ └── led-matrix-8x8-max7219-char.ino ├── led-matrix-8x8-max7219-pixel │ └── led-matrix-8x8-max7219-pixel.ino ├── led-matrix-8x8-max7219-smile │ └── led-matrix-8x8-max7219-smile.ino ├── led-matrix-8x8-smile-move │ └── led-matrix-8x8-smile-move.ino └── led-matrix-8x8-smile │ └── led-matrix-8x8-smile.ino ├── LED.RGB_lesson ├── ardu-rgb-cycle3 │ └── ardu-rgb-cycle3.ino ├── ardu-rgb-cycle3m │ └── ardu-rgb-cycle3m.ino ├── ardu-rgb-rainbow │ └── ardu-rgb-rainbow.ino └── ardu-rgb │ └── ardu-rgb.ino ├── LED.ROC.Led_Matrix_lesson ├── matrix8x8-basic-opt │ └── matrix8x8-basic-opt.ino ├── matrix8x8-basic │ └── matrix8x8-basic.ino ├── matrix8x8-count │ └── matrix8x8-count.ino ├── matrix8x8-heart │ └── matrix8x8-heart.ino ├── matrix8x8-scan │ └── matrix8x8-scan.ino └── matrix8x8 │ └── matrix8x8.ino ├── LED.TM1637_article ├── TM1637_1234 │ └── TM1637_1234.ino ├── TM1637_Alarm │ └── TM1637_Alarm.ino └── TM1637_Clock │ └── TM1637_Clock.ino ├── LED.WS2812_lesson └── ws2812_test │ └── ws2812_test.ino │ └── ws2812_test.ino.ino ├── Link.Bluetooth ├── btrepeater │ └── btrepeater.ino └── hc05_pairing │ └── hc05_pairing.ino ├── Link.HC-05_lesson ├── bt_dim │ └── bt_dim.ino ├── bt_led │ └── bt_led.ino └── bt_robot │ └── bt_robot.ino ├── Link.IR38 └── rawirdecode │ ├── rawirdecode.ino │ └── rawirdecodestruct.ino_ ├── Link.IRLink_lesson ├── photo_analog │ └── photo_analog.ino ├── photo_basic │ └── photo_basic.ino ├── photo_serial │ └── photo_serial.ino ├── photo_tr_basic │ └── photo_tr_basic.ino └── photo_tr_serial │ └── photo_tr_serial.ino ├── Link.NRF24_lesson ├── nrf24-receiver-lcd-to │ ├── nrf24-receiver-lcd-to.ino │ └── printf.h ├── nrf24-receiver-lcd │ └── nrf24-receiver-lcd.ino ├── nrf24-receiver │ └── nrf24-receiver.ino ├── nrf24-transmitter-lcd │ └── nrf24-transmitter-lcd.ino ├── nrf24-transmitter │ └── nrf24-transmitter.ino ├── nrf24_pot_control │ └── nrf24_pot_control.ino ├── nrflnatx │ └── nrflnatx.ino └── nrflnaty │ ├── nRF2401.h │ └── nrflnaty.ino ├── Link.RF5-433 ├── rf433rec │ └── rf433rec.ino └── rf5tr │ └── rf5tr.ino ├── Link.RS485_lesson ├── rs485_ping │ └── rs485_ping.ino ├── rs485_pong │ └── rs485_pong.ino ├── rs485_receive │ └── rs485_receive.ino └── rs485_transmit │ └── rs485_transmit.ino ├── Link.SFlow ├── SFlow_adxl345 │ └── SFlow_adxl345.ino ├── SFlow_position_test │ └── SFlow_position_test.ino ├── SFlow_simple_test │ └── SFlow_simple_test.ino ├── SFlow_vector_test │ └── SFlow_vector_test.ino ├── aplot_sflow_adxl │ └── aplot_sflow_adxl.ino ├── sflow-receiver │ └── sflow-receiver.ino ├── sflow-transmitter │ └── sflow-transmitter.ino ├── sflow_simple_adc │ └── sflow_simple_adc.ino ├── sfmon_sflow_adxl │ └── sfmon_sflow_adxl.ino ├── sfmon_sflow_adxlf │ └── sfmon_sflow_adxlf.ino └── sfmon_sflow_hum_temp │ └── sfmon_sflow_hum_temp.ino ├── Link.UART_lesson ├── serial_first │ └── serial_first.ino ├── serial_master │ └── serial_master.ino ├── serial_master_photo │ └── serial_master_photo.ino ├── serial_slave │ └── serial_slave.ino ├── serial_slave_photo │ └── serial_slave_photo.ino ├── serial_test_master │ └── serial_test_master.ino ├── serial_test_slave │ └── serial_test_slave.ino ├── uart_master │ └── uart_master.ino └── uart_master_fflop │ └── uart_master_fflop.ino ├── Motor.L298N_lesson └── l298n-simple │ └── l298n-simple.ino ├── Motor.ROC.TB6612_lesson └── test │ └── test.ino ├── Motor.ROC.servo_lesson └── servo_test │ ├── config.h │ └── servo_test.ino ├── Motor.Servo_lesson └── ardu-servo-photo │ └── ardu-servo-photo.ino ├── Motor.Stepper ├── step-cnc-shield │ └── step-cnc-shield.ino ├── step │ └── step.ino ├── stepper_control_A4988 │ └── stepper_control_A4988.ino └── stepper_uln │ └── stepper_uln.ino ├── OSD ├── ArduCam_Max7456.cpp ├── ArduCam_Max7456.h ├── OSD.ino ├── Spi.cpp └── Spi.h ├── PWM_lesson └── pwm-monit │ └── pwm-monit.ino ├── Piano_article └── piano │ └── piano.ino ├── ROC.GPIO_Expander_lesson ├── ROC.Expander │ └── ROC.Expander.ino ├── expander-btn │ └── expander-btn.ino ├── expander-int │ └── expander-int.ino └── expander-led │ └── expander-led.ino ├── SDCard_lesson ├── CardInfo │ └── CardInfo.ino ├── Datalogger │ └── Datalogger.ino ├── Datalogger_ds18b20 │ └── Datalogger_ds18b20.ino └── ReadWrite │ └── ReadWrite.ino ├── Segway_mpu ├── Madgwick.cpp ├── Madgwick.h └── segway_mpu.ino ├── Sensor.Comp_Filter_article ├── compl │ └── compl.ino ├── compl_1 │ └── compl_1.ino └── compl_diff │ └── compl_diff.ino ├── Sensor.DHT11_lesson ├── arduino-dht11-lcd │ └── arduino-dht11-lcd.ino └── arduino-dht11 │ └── arduino-dht11.ino ├── Sensor.DS18B20_lesson └── ardu-ds18b20 │ └── ardu-ds18b20.ino ├── Sensor.LPF_lesson ├── lpf_mpu6050 │ └── lpf_mpu6050.ino ├── lpf_pot │ └── lpf_pot.ino └── lpf_pot_diff │ └── lpf_pot_diff.ino ├── Sensor.MLX90620_lesson ├── MLX90620_Example │ ├── MLX90620_Example.ino │ └── MLX90620_registers.h └── MLX90620_alphaCalculator │ ├── MLX90620_alphaCalculator.ino │ └── MLX90620_registers.h ├── Sensor.MPU6050_lesson ├── mpu6050 │ └── mpu6050.ino └── mpu6050_raw │ └── mpu6050_raw.ino ├── Sensor.Madgwick_article ├── MadgwickAHRS │ ├── MadgwickAHRS.cpp │ ├── MadgwickAHRS.h │ ├── README.md │ ├── examples │ │ └── MPU6050Test │ │ │ └── MPU6050Test.ino │ ├── keywords.txt │ └── library.properties ├── imu_madgwick │ ├── Madgwick.cpp │ ├── Madgwick.h │ ├── imu_madgwick.ino │ └── readme.txt ├── imu_madgwick_z │ ├── Madgwick.cpp │ ├── Madgwick.h │ ├── imu_madgwick_z.ino │ └── utils.h ├── madgwick_mount │ └── madgwick_mount.ino └── madgwick_test │ └── madgwick_test.ino ├── Sensor.ROC.BME280_lesson └── BME280_test │ └── BME280_test.ino ├── Sensor.ROC.BMP280_lesson ├── bmp280test │ └── bmp280test.ino └── bmp280testSPI │ └── bmp280testSPI.ino ├── Sensor.TSL1401_lesson ├── TSL1401 │ └── TSL1401.ino ├── TSL1401_ │ └── TSL1401_.ino ├── TSL1401_SFMonitor │ └── TSL1401_SFMonitor.ino └── TSL1401_SFMonitor_oneshot │ └── TSL1401_SFMonitor_oneshot.ino ├── Sensor.TSL2561_lesson └── tsl2561 │ └── tsl2561.ino ├── Sensor.Thermistor_NTC_lesson ├── thermistor-100k-t │ └── thermistor-100k-t.ino ├── thermistor-100k-ta │ └── thermistor-100k-ta.ino └── thermistor-100k │ └── thermistor-100k.ino ├── Sound ├── bit8mario │ └── bit8mario.ino ├── bit8mario_2 │ └── bit8mario_2.ino ├── starwars │ └── starwars.ino └── wav │ └── wav.ino ├── Speaker_lesson ├── metronome │ └── metronome.ino ├── notes │ └── notes.ino └── starwars │ └── starwars.ino ├── ThermoV └── ThermoV.ino ├── Timeout_lesson ├── Blink2_timeout │ └── Blink2_timeout.ino └── Blink_timeout │ └── Blink_timeout.ino ├── blocks_servo_sweep └── blocks_servo_sweep.ino ├── esc_test_2 └── esc_test_2.ino ├── head ├── SoftwareServos.h └── head.ino ├── heart └── heart.ino ├── i2c_scanner └── i2c_scanner.ino ├── motor_l293d_1 └── motor_l293d_1.ino ├── photodiode_lesson └── photodiode_lesson.ino ├── ppm_pwm └── ppm_pwm.ino ├── rgb_control └── rgb_control.ino ├── rgb_ring └── rgb_ring.ino ├── tank └── tank.ino ├── track_bot_l298P └── track_bot_l298P.ino ├── weather_ctrl └── weather_ctrl.ino └── weather_sirena └── weather_sirena.ino /libs/Adafruit_GFX/README.txt: -------------------------------------------------------------------------------- 1 | This is the core graphics library for all our displays, providing basic graphics primitives (points, lines, circles, etc.). It needs to be paired with a hardware-specific library for each display device we carry (handling the lower-level functions). 2 | 3 | Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit! 4 | 5 | Written by Limor Fried/Ladyada for Adafruit Industries. 6 | BSD license, check license.txt for more information. 7 | All text above must be included in any redistribution. 8 | 9 | To download, click the DOWNLOAD ZIP button, uncompress and rename the uncompressed folder Adafruit_GFX. Confirm that the Adafruit_GFX folder contains Adafruit_GFX.cpp and Adafruit_GFX.h 10 | 11 | Place the Adafruit_GFX library folder your /Libraries/ folder. You may need to create the Libraries subfolder if its your first library. Restart the IDE. 12 | -------------------------------------------------------------------------------- /libs/Adafruit_GFX/license.txt: -------------------------------------------------------------------------------- 1 | Software License Agreement (BSD License) 2 | 3 | Copyright (c) 2012, Adafruit Industries. All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 3. Neither the name of the copyright holders nor the names of its 13 | contributors may be used to endorse or promote products derived from 14 | this software without specific prior written permission. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY 17 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY 20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /libs/Adafruit_ST7735/README.txt: -------------------------------------------------------------------------------- 1 | This is a library for the Adafruit 1.8" SPI display. 2 | This library works with the Adafruit 1.8" TFT Breakout w/SD card 3 | ----> http://www.adafruit.com/products/358 4 | as well as Adafruit raw 1.8" TFT display 5 | ----> http://www.adafruit.com/products/618 6 | 7 | Check out the links above for our tutorials and wiring diagrams. 8 | These displays use SPI to communicate, 4 or 5 pins are required 9 | to interface (RST is optional). 10 | Adafruit invests time and resources providing this open source code, 11 | please support Adafruit and open-source hardware by purchasing 12 | products from Adafruit! 13 | 14 | Written by Limor Fried/Ladyada for Adafruit Industries. 15 | MIT license, all text above must be included in any redistribution 16 | 17 | To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_ST7735. Check that the Adafruit_ST7735 folder contains Adafruit_ST7735.cpp and Adafruit_ST7735. 18 | 19 | Place the Adafruit_ST7735 library folder your /libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE 20 | 21 | Also requires the Adafruit_GFX library for Arduino. 22 | -------------------------------------------------------------------------------- /libs/SerialFlow/SerialFlow.h: -------------------------------------------------------------------------------- 1 | /* 2 | SerialFlow.h - Communication library with packages of values. 3 | Created by Oleg Evsegneev, September, 2012. 4 | Last update 13.11.2016 5 | Released into the public domain. 6 | Ver 0.8 (for Arduino) 7 | */ 8 | #ifndef SerialFlow_h 9 | #define SerialFlow_h 10 | 11 | #include "Arduino.h" 12 | 13 | // uncomment desired library 14 | //#include 15 | //#include 16 | #include 17 | 18 | #define MAX_PACKET_SIZE 8 19 | 20 | #if defined __RF24_H__ 21 | #define RF24_REPEAT_COUNT 1 22 | #define RF24_REPEAT_DELAY 15 23 | #define RF24_PAYLOAD 1 24 | #endif 25 | 26 | class SerialFlow { 27 | public: 28 | #if defined FastSerial_h 29 | SerialFlow( FastSerial *serial ); 30 | #elif defined __RF24_H__ 31 | SerialFlow( uint8_t cn, uint8_t csn ); 32 | #else 33 | SerialFlow( HardwareSerial *serial ); 34 | #endif 35 | 36 | /** Set data packet format 37 | * 38 | * @param v_length Length of value in bytes. 39 | * @param p_size Number of values. 40 | * @param separate Flag to separate values by 0x10 char (optional). 41 | */ 42 | void setPacketFormat( uint8_t v_length, uint8_t p_size, boolean separate ); 43 | void setPacketFormat( uint8_t v_length, uint8_t p_size ); 44 | 45 | /** Initialize port 46 | * @param baud_rate Serial port baud rate. 47 | */ 48 | #ifdef __RF24_H__ 49 | void begin( uint64_t address1, uint64_t address2 ); 50 | #else 51 | void begin( uint32_t baud_rate ); 52 | #endif 53 | 54 | /** Set value to data packet 55 | * 56 | * @param value Value. 57 | */ 58 | void setPacketValue(uint32_t value); 59 | 60 | /** Send packet to serial port 61 | */ 62 | void sendPacket(); 63 | 64 | /** Receive packet from serial port 65 | */ 66 | bool receivePacket(); 67 | 68 | /** Get received packet 69 | * @param idx Index of value from packet. 70 | */ 71 | uint32_t getPacketValue( uint8_t idx ); 72 | 73 | /** Serial write 74 | * @param v Byte to send. 75 | */ 76 | void write( uint8_t v ); 77 | 78 | /** Serial read 79 | */ 80 | uint8_t read(); 81 | 82 | void getHWInfo(); 83 | 84 | protected: 85 | #ifdef FastSerial_h 86 | FastSerial *_serial; 87 | #elif defined __RF24_H__ 88 | RF24 *_serial; 89 | #else 90 | HardwareSerial *_serial; 91 | #endif 92 | 93 | boolean _separate; 94 | uint8_t _p_size; 95 | uint8_t _v_length; 96 | 97 | uint32_t _vs[MAX_PACKET_SIZE]; 98 | uint8_t _vs_idx; 99 | 100 | uint32_t _vr[MAX_PACKET_SIZE]; 101 | uint8_t _vr_val[4]; 102 | uint8_t _vr_idx; 103 | uint8_t _cr_idx; 104 | bool _escape; 105 | bool _collecting; 106 | 107 | 108 | uint32_t _join_bytes(uint8_t *bs); 109 | }; 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /libs/SerialFlow/readme.txt: -------------------------------------------------------------------------------- 1 | SerialFlow library for Arduino 2 | 3 | Uses to transmit packed data. 4 | 5 | You need to uncomment one of the #include directives in SerialFlow.h file in order to use nrf24 radio or FastSerial library. 6 | 7 | For example: 8 | // uncomment desired library 9 | //#include 10 | //#include 11 | 12 | #include -------------------------------------------------------------------------------- /libs/digitalWriteFast/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For DigitalWriteFast 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | DigitalWriteFast KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | digitalWriteFast KEYWORD2 16 | pinModeFast KEYWORD2 17 | digitalReadFast KEYWORD2 18 | noAnalogWrite KEYWORD2 -------------------------------------------------------------------------------- /sketches/ADC_lesson/adc/adc.ino: -------------------------------------------------------------------------------- 1 | byte adcPin = A0; 2 | int val; 3 | 4 | void setup() { 5 | Serial.begin(9600); 6 | pinMode(adcPin, INPUT); 7 | } 8 | 9 | void loop() { 10 | val = analogRead(adcPin); 11 | Serial.println(val); 12 | delay(100); 13 | } 14 | -------------------------------------------------------------------------------- /sketches/ADC_lesson/adc_lesson/adc_lesson.ino: -------------------------------------------------------------------------------- 1 | int val = 0; 2 | 3 | void setup() { 4 | Serial.begin(9600); 5 | pinMode(A0, INPUT); 6 | } 7 | 8 | void loop() { 9 | val = analogRead(A0); 10 | Serial.println((5/1024.0)*val); 11 | delay(1000); 12 | } 13 | -------------------------------------------------------------------------------- /sketches/AS5048a/AS5048a.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | 4 | AS5048A angleSensor(8); 5 | 6 | void setup() 7 | { 8 | Serial.begin(19200); 9 | angleSensor.init(); 10 | } 11 | 12 | void loop() 13 | { 14 | delay(1000); 15 | if (Serial.available()) { 16 | word val = angleSensor.getRawRotation(); 17 | val = map(val, 0, 16383, 0, (200 * 16 - 1)); 18 | Serial.print("Got rotation of: "); 19 | Serial.println(val, DEC); 20 | Serial.print("State: "); 21 | angleSensor.printState(); 22 | Serial.print("Errors: "); 23 | Serial.println(angleSensor.getErrors()); 24 | } 25 | } 26 | 27 | -------------------------------------------------------------------------------- /sketches/Baro_Comp_article/baro_BMP180_slave/baro_BMP180_slave.ino: -------------------------------------------------------------------------------- 1 | #define CMD_REQ 0xA1 2 | #define CMD_ANS 0xA2 3 | 4 | static const byte PACKET_SIZE = 3; 5 | static const byte VALUE_SIZE = 4; 6 | static const boolean SEPARATE_VALUES = false; 7 | 8 | #include 9 | #include 10 | #include 11 | 12 | SFE_BMP180 pressure; 13 | SerialFlow rd(&Serial); 14 | 15 | const int led = 13; 16 | 17 | void blink(int n, int d){ 18 | for(int i=0; i 9 | #include 10 | #include 11 | 12 | MS5611 ms5611; 13 | SerialFlow rd(&Serial); 14 | 15 | const int led = 13; 16 | 17 | void blink(int n, int d){ 18 | for(int i=0; i 2 | #include "RTClib.h" 3 | 4 | RTC_DS3231 rtc; 5 | 6 | void setup () { 7 | Serial.begin(9600); 8 | 9 | delay(3000); 10 | 11 | if (! rtc.begin()) { 12 | Serial.println("Couldn't find RTC"); 13 | while (1); 14 | } 15 | } 16 | 17 | void loop () { 18 | DateTime now = rtc.now(); 19 | 20 | Serial.print(now.day(), DEC); 21 | Serial.print('.'); 22 | Serial.print(now.month(), DEC); 23 | Serial.print('.'); 24 | Serial.print(now.year(), DEC); 25 | Serial.print(' '); 26 | Serial.print(now.hour(), DEC); 27 | Serial.print(':'); 28 | Serial.print(now.minute(), DEC); 29 | Serial.print(':'); 30 | Serial.print(now.second(), DEC); 31 | Serial.println(); 32 | delay(1000); 33 | } 34 | -------------------------------------------------------------------------------- /sketches/Display.LCD1602_lesson/ardu-lcd-text-2/ardu-lcd-text-2.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 4 | 5 | void setup() { 6 | lcd.begin(16, 2); 7 | } 8 | 9 | void loop() { 10 | lcd.clear(); 11 | lcd.print("RobotClass.ru"); 12 | lcd.setCursor(0, 1); 13 | lcd.print("timer - "); 14 | lcd.setCursor(8, 1); 15 | lcd.print(millis() / 1000); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /sketches/Display.LCD1602_lesson/ardu-lcd-text/ardu-lcd-text.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 4 | 5 | void setup() { 6 | lcd.begin(16, 2); 7 | lcd.print("RobotClass.ru"); 8 | } 9 | 10 | void loop() { 11 | lcd.setCursor(0, 1); 12 | lcd.print(millis() / 1000); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /sketches/Display.NOKIA5110_lesson/nokia5110/nokia5110.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | // pin 3 - Serial clock out (SCLK) 5 | // pin 4 - Serial data out (DIN) 6 | // pin 5 - Data/Command select (D/C) 7 | // pin 6 - LCD chip select (CS) 8 | // pin 7 - LCD reset (RST) 9 | Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 6, 7); 10 | 11 | const unsigned char PROGMEM logoBmp[] = { 12 | B11111111, B11111111, B10000000, 13 | B11111111, B11111111, B10000000, 14 | B11111111, B11111111, B10000000, 15 | B11111100, B00000011, B10000000, 16 | B11111000, B00000001, B10000000, 17 | B11111100, B00000011, B10000000, 18 | B11111111, B11000011, B10000000, 19 | B11111111, B10000111, B10000000, 20 | B11111111, B10001111, B10000000, 21 | B11111111, B00001111, B10000000, 22 | B11111110, B00011111, B10000000, 23 | B11111110, B00011111, B10000000, 24 | B11111100, B00111111, B10000000, 25 | B11111100, B01111111, B10000000, 26 | B11111000, B00000011, B10000000, 27 | B11111000, B00000001, B10000000 28 | }; 29 | 30 | void setup() { 31 | Serial.begin(9600); 32 | 33 | // Инициализация дисплея 34 | display.begin(); 35 | 36 | // Очищаем дисплей 37 | display.clearDisplay(); 38 | display.display(); 39 | 40 | // Устанавливаем контраст 41 | display.setContrast(50); 42 | delay(1000); 43 | } 44 | 45 | 46 | void loop() { 47 | // Рисуем заранее подготовленное лого 48 | // Подготовлен массив из 16 пар байтов 49 | // каждый байт состоит из 8 битов, соответсвенно 50 | // получаем матрицу 16х16 битов, 1-черный цвет, 0-белый цвет 51 | display.drawBitmap(LCDWIDTH/2-8, LCDHEIGHT/2-8, logoBmp, 24, 16, BLACK); // x, y, logo, w, h, color 52 | display.display(); 53 | delay(10000); 54 | // Очищаем дисплей 55 | display.clearDisplay(); 56 | display.display(); 57 | delay(1000); 58 | } 59 | -------------------------------------------------------------------------------- /sketches/Display.NOKIA5110_lesson/nokia5110_prim/nokia5110_prim.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 6, 7); 5 | 6 | void setup() { 7 | // Инициализация дисплея 8 | display.begin(); 9 | 10 | // Очищаем дисплей 11 | display.clearDisplay(); 12 | display.display(); 13 | 14 | display.setContrast(50); 15 | delay(1000); 16 | } 17 | 18 | 19 | void loop() { 20 | // пиксел 21 | display.clearDisplay(); 22 | display.drawPixel(10, 10, BLACK); 23 | display.display(); 24 | delay(1000); 25 | 26 | // линия 27 | display.clearDisplay(); 28 | display.drawLine(0, 0, 50, 30, BLACK); 29 | display.display(); 30 | delay(1000); 31 | 32 | // прямоугольник 33 | display.clearDisplay(); 34 | display.drawRect(0, 0, 10, 10, BLACK); 35 | display.display(); 36 | delay(1000); 37 | 38 | // прямоугольник залитый 39 | display.clearDisplay(); 40 | display.fillRect(0, 0, 10, 10, BLACK); 41 | display.display(); 42 | delay(1000); 43 | 44 | // треугольник 45 | display.clearDisplay(); 46 | display.drawTriangle(0, 0, 40, 40, 30, 20, BLACK); 47 | display.display(); 48 | delay(1000); 49 | 50 | // окружность в центре 51 | display.clearDisplay(); 52 | display.drawCircle(display.width()/2, display.height()/2, 10, BLACK); 53 | display.display(); 54 | delay(1000); 55 | } 56 | 57 | -------------------------------------------------------------------------------- /sketches/Display.NOKIA5110_lesson/nokia5110_smile/nokia5110_smile.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 6, 7); 5 | 6 | const unsigned char PROGMEM logoBmp[] = { 7 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 8 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 9 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 10 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 11 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 12 | 0x0, 0x0, 0x0, 0xf, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 13 | 0x0, 0x0, 0x0, 0x1f, 0x80, 0x0, 0x0, 0x3c, 0x0, 0x0, 0x0, 14 | 0x0, 0x0, 0x0, 0x3f, 0xc0, 0x0, 0x0, 0x7e, 0x0, 0x0, 0x0, 15 | 0x0, 0x0, 0x0, 0x3f, 0xc0, 0x0, 0x0, 0xfe, 0x0, 0x0, 0x0, 16 | 0x0, 0x0, 0x0, 0x79, 0xc0, 0x0, 0x0, 0xff, 0x0, 0x0, 0x0, 17 | 0x0, 0x0, 0x0, 0x71, 0xc0, 0x0, 0x1, 0xef, 0x0, 0x0, 0x0, 18 | 0x0, 0x0, 0x0, 0x73, 0xc0, 0x0, 0x1, 0xc7, 0x0, 0x0, 0x0, 19 | 0x0, 0x0, 0x0, 0x73, 0xc0, 0x0, 0x1, 0xc7, 0x0, 0x0, 0x0, 20 | 0x0, 0x0, 0x0, 0x7f, 0x80, 0x0, 0x1, 0xef, 0x0, 0x0, 0x0, 21 | 0x0, 0x0, 0x0, 0x7f, 0x0, 0x0, 0x0, 0xfe, 0x0, 0x0, 0x0, 22 | 0x0, 0x0, 0x0, 0x3f, 0x0, 0x0, 0x0, 0xfc, 0x0, 0x0, 0x0, 23 | 0x0, 0x0, 0x0, 0x1e, 0x0, 0x0, 0x0, 0x78, 0x0, 0x0, 0x0, 24 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 25 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 26 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 27 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 28 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 29 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 30 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 31 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 32 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 33 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 34 | 0x0, 0x0, 0x1c, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 35 | 0x0, 0x0, 0x1f, 0x80, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 36 | 0x0, 0x0, 0xf, 0xf0, 0x0, 0x0, 0x0, 0x1, 0xe0, 0x0, 0x0, 37 | 0x0, 0x0, 0x3, 0xff, 0x0, 0x0, 0x0, 0xff, 0xf0, 0x0, 0x0, 38 | 0x0, 0x0, 0x0, 0x7f, 0xfc, 0x0, 0x7, 0xff, 0xe0, 0x0, 0x0, 39 | 0x0, 0x0, 0x0, 0xf, 0xff, 0xff, 0xff, 0xfe, 0x0, 0x0, 0x0, 40 | 0x0, 0x0, 0x0, 0x1, 0xff, 0xff, 0xff, 0x80, 0x0, 0x0, 0x0, 41 | 0x0, 0x0, 0x0, 0x0, 0x3, 0xff, 0xf8, 0x0, 0x0, 0x0, 0x0, 42 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 43 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 44 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 45 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 46 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 47 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 48 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 49 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 50 | 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 51 | }; 52 | 53 | void setup() { 54 | // инициализация и очистка дисплея 55 | display.begin(); 56 | display.clearDisplay(); 57 | display.display(); 58 | 59 | // установка контраста 60 | display.setContrast(50); 61 | delay(1000); 62 | 63 | // отрисовка изображения 64 | display.drawBitmap(0, 0, logoBmp, 84, 44, BLACK); // x, y, logo, w, h, color 65 | display.display(); 66 | } 67 | 68 | void loop() { 69 | } 70 | -------------------------------------------------------------------------------- /sketches/Display.NOKIA5110_lesson/nokia5110_snake/Matrix3216.h: -------------------------------------------------------------------------------- 1 | #ifndef _Matrix3216_h_ 2 | #define _Matrix3216_h_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define COLOR_RED 7 9 | #define COLOR_GREEN 6 10 | #define COLOR_BLUE 5 11 | #define COLOR_BLACK 0 12 | 13 | // block map 14 | const byte trans[8][2] = {{0,8},{0,0},{4,8},{4,0}, 15 | {8,8},{8,0},{12,8},{12,0}}; 16 | 17 | class Matrix3216 { 18 | public: 19 | Matrix3216(int CR, int CG, int CB, int AA, int AB, int AC, int OE, int ST, int CLK); 20 | void setup(); 21 | void setFrame(byte *frame); 22 | void drawFrame(); 23 | void clearPixel(byte x, byte y); 24 | void clearPixel(byte x, byte y, byte color); 25 | void setPixel(byte x, byte y, byte color); 26 | 27 | private: 28 | byte *frame; 29 | int pinRGB[3]; 30 | int pinABC[3]; 31 | 32 | int pinOE = PD7; 33 | int pinST = PD6; 34 | int pinCLK = PD5; 35 | 36 | int row,block,bty,clr,bti; 37 | void dwrite(int pin, int val); 38 | void bwrite(int pin, int val); 39 | void addressRow(byte _address); 40 | void clock(); 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /sketches/Display.NOKIA5110_lesson/nokia5110_text/nokia5110_text.ino: -------------------------------------------------------------------------------- 1 | //#include 2 | #include 3 | #include 4 | 5 | Adafruit_PCD8544 display = Adafruit_PCD8544(3, 4, 5, 6, 7); 6 | 7 | void setup() { 8 | // инициализация и очистка дисплея 9 | display.begin(); 10 | display.clearDisplay(); 11 | display.display(); 12 | 13 | // установка контраста 14 | display.setContrast(20); 15 | delay(1000); 16 | 17 | display.setTextSize(1); // установка размера шрифта 18 | display.setTextColor(BLACK); // установка цвета текста 19 | display.setCursor(0,0); // установка цвета текста 20 | 21 | display.println("Hello, world!"); 22 | display.display(); 23 | } 24 | 25 | void loop() { 26 | } 27 | 28 | -------------------------------------------------------------------------------- /sketches/Display.OLED_RGB_article/test/test.ino: -------------------------------------------------------------------------------- 1 | #define BLACK 0x0000 2 | #define BLUE 0x001F 3 | #define RED 0xF800 4 | #define GREEN 0x07E0 5 | #define CYAN 0x07FF 6 | #define MAGENTA 0xF81F 7 | #define YELLOW 0xFFE0 8 | #define WHITE 0xFFFF 9 | 10 | #define sclk 13 11 | #define mosi 11 12 | #define cs 10 13 | #define rst 9 14 | #define dc 8 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | Adafruit_SSD1331 display = Adafruit_SSD1331(cs, dc, mosi, sclk, rst); 21 | 22 | void setup(void) { 23 | display.begin(); 24 | 25 | uint16_t time = millis(); 26 | display.fillScreen(BLACK); 27 | 28 | lcdTestPattern(); 29 | } 30 | 31 | void loop() { 32 | } 33 | 34 | void lcdTestPattern(void) 35 | { 36 | uint32_t i,j; 37 | display.goTo(0, 0); 38 | 39 | for(i=0;i<64;i++) 40 | { 41 | for(j=0;j<96;j++) 42 | { 43 | if(i>55){display.writeData(WHITE>>8);display.writeData(WHITE);} 44 | else if(i>47){display.writeData(BLUE>>8);display.writeData(BLUE);} 45 | else if(i>39){display.writeData(GREEN>>8);display.writeData(GREEN);} 46 | else if(i>31){display.writeData(CYAN>>8);display.writeData(CYAN);} 47 | else if(i>23){display.writeData(RED>>8);display.writeData(RED);} 48 | else if(i>15){display.writeData(MAGENTA>>8);display.writeData(MAGENTA);} 49 | else if(i>7){display.writeData(YELLOW>>8);display.writeData(YELLOW);} 50 | else {display.writeData(BLACK>>8);display.writeData(BLACK);} 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sketches/Display.OLED_lesson/OLED_game/OLED_game.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // If using software SPI (the default case): 7 | #define OLED_MOSI 9 8 | #define OLED_CLK 10 9 | #define OLED_DC 11 10 | #define OLED_CS 12 11 | #define OLED_RESET 13 12 | Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 13 | 14 | void setup() { 15 | display.begin(SSD1306_SWITCHCAPVCC); 16 | display.clearDisplay(); 17 | display.display(); 18 | 19 | delay(1000); 20 | 21 | } 22 | 23 | void loop() { 24 | for(int x=0; x<111; x++){ 25 | fillrect(x, 0, 16); 26 | display.display(); 27 | } 28 | } 29 | 30 | void fillrect(int x, int y, int s) { 31 | display.fillRect(x, y, x+s, y+s, WHITE); 32 | } 33 | -------------------------------------------------------------------------------- /sketches/Display.OLED_lesson/OLED_text/OLED_text.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | // If using software SPI (the default case): 7 | #define OLED_MOSI 9 8 | #define OLED_CLK 10 9 | #define OLED_DC 11 10 | #define OLED_CS 12 11 | #define OLED_RESET 13 12 | //Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS); 13 | Adafruit_SSD1306 display(4); 14 | 15 | void setup() { 16 | // инициализация и очистка дисплея 17 | display.begin(SSD1306_SWITCHCAPVCC, 0x3d); 18 | display.clearDisplay(); 19 | display.display(); 20 | 21 | delay(1000); 22 | 23 | display.setTextSize(1); // установка размера шрифта 24 | display.setTextColor(WHITE); // установка цвета текста 25 | display.setCursor(0,0); // установка курсора 26 | 27 | display.println("Hello, world!"); 28 | display.display(); 29 | } 30 | 31 | void loop() { 32 | } 33 | -------------------------------------------------------------------------------- /sketches/EEPROM_lesson/eeprom_put_int/eeprom_put_int.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const byte btnPin = 2; 4 | const byte potPin = A0; 5 | byte potIdx = 0; 6 | 7 | void setup() { 8 | Serial.begin(9600); 9 | pinMode(btnPin, INPUT); 10 | pinMode(potPin, INPUT); 11 | 12 | // считываем значения из EEPROM в цикле 13 | // сначала по адресу 0, потом 2, потом 4 14 | // i - интератор, он же номер потенциометра 15 | Serial.println("Read data from EEPROM"); 16 | for( byte i=0; i<3; i++ ){ 17 | int v; 18 | EEPROM.get(i*2, v); 19 | Serial.print("value of pot #"); 20 | Serial.print(i+1); 21 | Serial.print(" = "); 22 | Serial.println(v); 23 | } 24 | delay(3000); 25 | } 26 | 27 | void loop() { 28 | int v = analogRead(potPin); 29 | Serial.print("v = "); 30 | Serial.println(v); 31 | 32 | if( digitalRead(btnPin) == HIGH ){ 33 | EEPROM.put(potIdx*2, v); 34 | 35 | Serial.println("Write data to EEPROM"); 36 | Serial.print("value of pot #"); 37 | Serial.print(potIdx+1); 38 | Serial.print(" = "); 39 | Serial.println(v); 40 | 41 | if( potIdx == 2 ) 42 | potIdx = 0; 43 | else 44 | potIdx++; 45 | delay(1000); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sketches/EEPROM_lesson/eeprom_write/eeprom_write.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const byte btnPin = 2; 4 | byte counter = 0; 5 | int addr = 0; 6 | 7 | void setup() { 8 | Serial.begin(9600); 9 | pinMode(btnPin, INPUT); 10 | 11 | byte v = EEPROM.read(addr); 12 | Serial.print("saved counter = "); 13 | Serial.println(v); 14 | } 15 | 16 | void loop() { 17 | if( digitalRead(btnPin) == HIGH ){ 18 | counter++; 19 | 20 | EEPROM.write(addr, counter); 21 | 22 | Serial.print("counter = "); 23 | Serial.println(counter); 24 | delay(200); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sketches/EEPROM_lesson/eeprom_write_int/eeprom_write_int.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const byte btnPin = 2; 4 | const byte potPin = A0; 5 | byte potIdx = 0; 6 | 7 | void write_int(int addr, int v){ 8 | byte l, h; 9 | l = v & 0xFF; 10 | h = (v>>8) & 0xFF; 11 | EEPROM.write(addr, l); 12 | EEPROM.write(addr+1, h); 13 | } 14 | 15 | int read_int(int addr){ 16 | byte l, h; 17 | l = EEPROM.read(addr); 18 | h = EEPROM.read(addr+1); 19 | return l | (h<<8); 20 | } 21 | 22 | void setup() { 23 | Serial.begin(9600); 24 | pinMode(btnPin, INPUT); 25 | pinMode(potPin, INPUT); 26 | 27 | // считываем значения из EEPROM в цикле 28 | // сначала по адресу 0, потом 2, потом 4 29 | // i - интератор, он же номер потенциометра 30 | Serial.println("Read data from EEPROM"); 31 | for( byte i=0; i<3; i++ ){ 32 | int v = read_int(i*2); 33 | Serial.print("value of pot #"); 34 | Serial.print(i+1); 35 | Serial.print(" = "); 36 | Serial.println(v); 37 | } 38 | delay(3000); 39 | } 40 | 41 | void loop() { 42 | int v = analogRead(potPin); 43 | Serial.print("v = "); 44 | Serial.println(v); 45 | 46 | if( digitalRead(btnPin) == HIGH ){ 47 | write_int(potIdx*2, v); 48 | 49 | Serial.println("Write data to EEPROM"); 50 | Serial.print("value of pot #"); 51 | Serial.print(potIdx+1); 52 | Serial.print(" = "); 53 | Serial.println(v); 54 | 55 | if( potIdx == 2 ) 56 | potIdx = 0; 57 | else 58 | potIdx++; 59 | delay(1000); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sketches/Game.AlienInvaders_lesson/RobotClass-game-enemy/RobotClass-game-enemy.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define WIDTH 128 4 | #define HEIGHT 64 5 | #define UNIT_WIDTH 5 6 | #define UNIT_HEIGHT 4 7 | #define X 0 8 | #define Y 1 9 | #define CTRL_TO 50 10 | 11 | byte pinLeft = A0; 12 | byte pinRight = A1; 13 | 14 | byte player_coords[2]; 15 | byte enemy_coords[24][2]; 16 | unsigned long t, ctrl_next; 17 | 18 | byte player_sprite[UNIT_WIDTH*UNIT_HEIGHT] = { 19 | 0,0,1,0,0, 20 | 0,1,1,1,0, 21 | 0,1,0,1,0, 22 | 1,1,0,1,1 23 | }; 24 | 25 | byte enemy_sprite[UNIT_WIDTH*UNIT_HEIGHT] = { 26 | 1,0,1,0,1, 27 | 0,1,1,1,0, 28 | 0,1,0,1,0, 29 | 1,0,1,0,1 30 | }; 31 | 32 | Adafruit_SSD1306 display(4); 33 | 34 | void setup() { 35 | pinMode( pinLeft, INPUT ); 36 | pinMode( pinRight, INPUT ); 37 | 38 | // начальные координаты игрока 39 | player_coords[X] = WIDTH/2-UNIT_WIDTH/2; 40 | player_coords[Y] = HEIGHT-1-UNIT_HEIGHT; 41 | 42 | // начальные координаты врагов 43 | for( byte x=0; x<8; x++){ 44 | for( byte y=0; y<3; y++){ 45 | byte idx = x+y*8; 46 | enemy_coords[idx][X] = 5 + x*5+x*5; 47 | enemy_coords[idx][Y] = 5 + y*3+y*5; 48 | } 49 | } 50 | 51 | ctrl_next = millis() + CTRL_TO; 52 | 53 | // инициализация дисплея 54 | display.begin(SSD1306_SWITCHCAPVCC, 0x3D); 55 | display.clearDisplay(); 56 | } 57 | 58 | void loop() { 59 | unsigned long t = millis(); 60 | if( t > ctrl_next ){ 61 | ctrl_next = t + CTRL_TO; 62 | // обработка нажатий кнопок 63 | if( digitalRead(pinLeft) && player_coords[X]>0 ) 64 | player_coords[X] -= 1; 65 | if( digitalRead(pinRight) && player_coords[X] 2 | 3 | #define WIDTH 128 4 | #define HEIGHT 64 5 | #define UNIT_WIDTH 5 6 | #define UNIT_HEIGHT 4 7 | #define X 0 8 | #define Y 1 9 | #define CTRL_TO 50 10 | #define ENEMY_TO 1000 11 | 12 | byte pinLeft = A0; 13 | byte pinRight = A1; 14 | 15 | byte player_coords[2]; 16 | byte enemy_coords[24][2]; 17 | unsigned long t, ctrl_next, enemy_next; 18 | 19 | byte enemy_drift_x = 0; 20 | int enemy_drift_dir = 1; 21 | 22 | // спрайт игрока 23 | byte player_sprite[UNIT_WIDTH*UNIT_HEIGHT] = { 24 | 0,0,1,0,0, 25 | 0,1,1,1,0, 26 | 1,1,0,1,1, 27 | 1,1,0,1,1 28 | }; 29 | 30 | // спрайт врагов 31 | byte enemy_sprite[UNIT_WIDTH*UNIT_HEIGHT] = { 32 | 1,0,1,0,1, 33 | 0,1,1,1,0, 34 | 0,1,0,1,0, 35 | 1,0,1,0,1 36 | }; 37 | 38 | Adafruit_SSD1306 display(4); 39 | 40 | void enemyMove(){ 41 | if(enemy_drift_dir > 0 && enemy_drift_x < 40) 42 | enemy_drift_x += 1; 43 | else if(enemy_drift_dir < 0 && enemy_drift_x > 5) 44 | enemy_drift_x -= 1; 45 | else 46 | enemy_drift_dir = -1*enemy_drift_dir; 47 | } 48 | 49 | void handleControls(){ 50 | if( digitalRead(pinLeft) && player_coords[X]>0 ) 51 | player_coords[X] -= 1; 52 | else if( digitalRead(pinRight) && player_coords[X] ctrl_next ){ 96 | ctrl_next = t + CTRL_TO; 97 | 98 | handleControls(); // обработка нажатий кнопок 99 | 100 | display.clearDisplay(); // очистка фрейма 101 | drawPlayer(); // отрисовка игрока на фрейме 102 | drawEnemies(); // отрисовка врагов на фрейме 103 | display.display(); // вывод фрейма на дисплей 104 | } 105 | if( t > enemy_next ){ 106 | enemy_next = t + ENEMY_TO; 107 | enemyMove(); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /sketches/Game.AlienInvaders_lesson/RobotClass-game-player/RobotClass-game-player.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define WIDTH 128 4 | #define HEIGHT 64 5 | #define CTRL_TO 50 6 | 7 | byte pinLeft = A0; 8 | byte pinRight = A1; 9 | 10 | int x,y; 11 | unsigned long t, ctrl_next; 12 | 13 | #define OLED_RESET 4 14 | Adafruit_SSD1306 display(OLED_RESET); 15 | 16 | void setup() { 17 | pinMode( pinLeft, INPUT ); 18 | pinMode( pinRight, INPUT ); 19 | 20 | x = WIDTH/2; 21 | y = HEIGHT-1; 22 | ctrl_next = millis() + CTRL_TO; 23 | 24 | // инициализация дисплея 25 | display.begin(SSD1306_SWITCHCAPVCC, 0x3D); 26 | display.clearDisplay(); 27 | } 28 | 29 | void loop() { 30 | unsigned long t = millis(); 31 | if( t > ctrl_next ){ 32 | ctrl_next = t + CTRL_TO; 33 | // обработка нажатий кнопок 34 | if( digitalRead(pinLeft) && x>0 ) 35 | x = x - 1; 36 | if( digitalRead(pinRight) && x 2 | 3 | #define WIDTH 128 4 | #define HEIGHT 64 5 | #define PLAYER_WIDTH 5 6 | #define PLAYER_HEIGHT 4 7 | #define CTRL_TO 50 8 | 9 | byte pinLeft = A0; 10 | byte pinRight = A1; 11 | 12 | int x,y; 13 | unsigned long t, ctrl_next; 14 | 15 | byte player[PLAYER_WIDTH*PLAYER_HEIGHT] = { 16 | 0,0,1,0,0, 17 | 0,1,1,1,0, 18 | 0,1,0,1,0, 19 | 1,1,0,1,1 20 | }; 21 | 22 | #define OLED_RESET 4 23 | Adafruit_SSD1306 display(OLED_RESET); 24 | 25 | void setup() { 26 | pinMode( pinLeft, INPUT ); 27 | pinMode( pinRight, INPUT ); 28 | 29 | x = WIDTH/2-PLAYER_WIDTH/2; 30 | y = HEIGHT-1-PLAYER_HEIGHT; 31 | ctrl_next = millis() + CTRL_TO; 32 | 33 | // инициализация дисплея 34 | display.begin(SSD1306_SWITCHCAPVCC, 0x3D); 35 | display.clearDisplay(); 36 | } 37 | 38 | void loop() { 39 | unsigned long t = millis(); 40 | if( t > ctrl_next ){ 41 | ctrl_next = t + CTRL_TO; 42 | // обработка нажатий кнопок 43 | if( digitalRead(pinLeft) && x>0 ) 44 | x = x - 1; 45 | if( digitalRead(pinRight) && x 2 | #include "Adafruit_MQTT.h" 3 | #include "Adafruit_MQTT_Client.h" 4 | 5 | #include 6 | #include 7 | 8 | #define WLAN_SSID "makeitlab" 9 | #define WLAN_PASS "noumen2001" 10 | 11 | #define AIO_SERVER "45.86.181.43" 12 | #define AIO_SERVERPORT 1883 13 | #define AIO_USERNAME "puser" 14 | #define AIO_KEY "dEr40n" 15 | 16 | WiFiClient client; 17 | 18 | Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); 19 | Adafruit_MQTT_Publish temperature = Adafruit_MQTT_Publish(&mqtt, "bmp280/temp"); 20 | 21 | Adafruit_BMP280 bme; 22 | 23 | unsigned long pub_next_tm, tm; 24 | unsigned int pub_to = 5000; 25 | 26 | void setup() { 27 | Serial.begin(9600); 28 | 29 | // инициализация BMP280 30 | if (!bme.begin()) { 31 | while (1); 32 | } 33 | 34 | // инициализация WIFI 35 | delay(10); 36 | WiFi.begin(WLAN_SSID, WLAN_PASS); 37 | while (WiFi.status() != WL_CONNECTED) { 38 | delay(500); 39 | } 40 | Serial.println("connected to wifi"); 41 | } 42 | 43 | void loop() { 44 | tm = millis(); 45 | if( tm > pub_next_tm ){ 46 | pub_next_tm = tm + pub_to; 47 | MQTT_connect(); // подключаемся к брокеру 48 | float t = bme.readTemperature(); // считываем температуру 49 | Serial.print("t = "); 50 | Serial.println(t); 51 | temperature.publish(t); // публикуем mqtt сообщение 52 | } 53 | } 54 | 55 | void MQTT_connect() { 56 | int8_t ret; 57 | 58 | if (mqtt.connected()) { 59 | return; 60 | } 61 | 62 | uint8_t retries = 3; 63 | while ((ret = mqtt.connect()) != 0) { 64 | mqtt.disconnect(); 65 | delay(5000); 66 | retries--; 67 | if (retries == 0) { 68 | while (1); 69 | } 70 | } 71 | Serial.println("connected to mqtt"); 72 | } 73 | -------------------------------------------------------------------------------- /sketches/IOT.ESP32_MQTT_lesson/mqtt_publish_number/mqtt_publish_number.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Adafruit_MQTT.h" 3 | #include "Adafruit_MQTT_Client.h" 4 | 5 | #include 6 | #include 7 | 8 | #define WLAN_SSID "makeitlab" 9 | #define WLAN_PASS "noumen2001" 10 | 11 | #define AIO_SERVER "mqtt.robotclass.ru" 12 | #define AIO_SERVERPORT 1883 13 | #define AIO_USERNAME "fred" 14 | #define AIO_KEY "123" 15 | 16 | WiFiClient client; 17 | 18 | Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); 19 | Adafruit_MQTT_Publish counter = Adafruit_MQTT_Publish(&mqtt, "counter"); 20 | 21 | unsigned long pub_next_tm, tm; 22 | unsigned int pub_to = 5000; 23 | unsigned int cnt = 0; 24 | 25 | void setup() { 26 | Serial.begin(9600); 27 | 28 | // инициализация WIFI 29 | delay(10); 30 | WiFi.begin(WLAN_SSID, WLAN_PASS); 31 | while (WiFi.status() != WL_CONNECTED) { 32 | delay(500); 33 | } 34 | Serial.println("connected to wifi"); 35 | } 36 | 37 | void loop() { 38 | tm = millis(); 39 | if( tm > pub_next_tm ){ 40 | pub_next_tm = tm + pub_to; 41 | MQTT_connect(); // подключаемся к брокеру 42 | Serial.println(cnt); 43 | counter.publish(cnt); // публикуем mqtt сообщение 44 | cnt++; 45 | } 46 | } 47 | 48 | void MQTT_connect() { 49 | int8_t ret; 50 | 51 | if (mqtt.connected()) { 52 | return; 53 | } 54 | 55 | uint8_t retries = 3; 56 | while ((ret = mqtt.connect()) != 0) { 57 | mqtt.disconnect(); 58 | delay(5000); 59 | retries--; 60 | if (retries == 0) { 61 | while (1); 62 | } 63 | } 64 | Serial.println("connected to mqtt"); 65 | } 66 | -------------------------------------------------------------------------------- /sketches/IOT.ESP_MQTT_lesson/mqtt/mqtt.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SimpleMQTTClient.ino 3 | The purpose of this exemple is to illustrate a simple handling of MQTT and Wifi connection. 4 | Once it connects successfully to a Wifi network and a MQTT broker, it subscribe to a topic and send a message to it. 5 | It will also send a message delayed 5 seconds later. 6 | */ 7 | 8 | #include "EspMQTTClient.h" 9 | 10 | EspMQTTClient client( 11 | "WifiSSID", 12 | "WifiPassword", 13 | "192.168.88.248", // MQTT Broker server ip 14 | "", // Can be omitted if not needed 15 | "", // Can be omitted if not needed 16 | "TestClient", // Client name that uniquely identify your device 17 | 1883 // The MQTT port, default to 1883. this line can be omitted 18 | ); 19 | 20 | void setup() 21 | { 22 | Serial.begin(115200); 23 | 24 | // Optionnal functionnalities of EspMQTTClient : 25 | client.enableDebuggingMessages(); // Enable debugging messages sent to serial output 26 | client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overrited with enableHTTPWebUpdater("user", "password"). 27 | client.enableLastWillMessage("TestClient/lastwill", "I am going offline"); // You can activate the retain flag by setting the third parameter to true 28 | } 29 | 30 | // This function is called once everything is connected (Wifi and MQTT) 31 | // WARNING : YOU MUST IMPLEMENT IT IF YOU USE EspMQTTClient 32 | void onConnectionEstablished() 33 | { 34 | // Subscribe to "mytopic/test" and display received message to Serial 35 | /* 36 | client.subscribe("mytopic/test", [](const String & payload) { 37 | Serial.println(payload); 38 | }); 39 | 40 | // Subscribe to "mytopic/wildcardtest/#" and display received message to Serial 41 | client.subscribe("mytopic/wildcardtest/#", [](const String & topic, const String & payload) { 42 | Serial.println(topic + ": " + payload); 43 | }); 44 | 45 | // Publish a message to "mytopic/test" 46 | client.publish("mytopic/test", "This is a message"); // You can activate the retain flag by setting the third parameter to true 47 | */ 48 | // Execute delayed instructions 49 | client.executeDelayed(5 * 1000, []() { 50 | //client.publish("mytopic/test", "This is a message sent 5 seconds later"); 51 | client.publish("mytopic/test", "ok"); 52 | }); 53 | } 54 | 55 | void loop() 56 | { 57 | client.loop(); 58 | } 59 | -------------------------------------------------------------------------------- /sketches/IOT.ESP_MQTT_lesson/mqtt_publish/mqtt_publish.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Adafruit_MQTT.h" 3 | #include "Adafruit_MQTT_Client.h" 4 | 5 | #define WLAN_SSID "X-COM-CITADEL" 6 | #define WLAN_PASS "id7dq8d!" 7 | 8 | #define AIO_SERVER "192.168.88.248" 9 | #define AIO_SERVERPORT 1883 // use 8883 for SSL 10 | #define AIO_USERNAME "" 11 | #define AIO_KEY "" 12 | 13 | WiFiClient client; 14 | //WiFiClientSecure client; 15 | 16 | Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); 17 | Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/photocell"); 18 | 19 | unsigned long pub_next_tm, tm; 20 | unsigned int pub_to = 1000; 21 | 22 | //void MQTT_connect(); 23 | 24 | void setup() { 25 | Serial.begin(115200); 26 | delay(10); 27 | 28 | Serial.println(F("Adafruit MQTT demo")); 29 | 30 | Serial.println(); Serial.println(); 31 | Serial.print("Connecting to "); 32 | Serial.println(WLAN_SSID); 33 | 34 | WiFi.begin(WLAN_SSID, WLAN_PASS); 35 | while (WiFi.status() != WL_CONNECTED) { 36 | delay(500); 37 | Serial.print("."); 38 | } 39 | Serial.println(); 40 | 41 | Serial.println("WiFi connected"); 42 | Serial.println("IP address: "); Serial.println(WiFi.localIP()); 43 | } 44 | 45 | uint32_t x=0; 46 | 47 | void loop() { 48 | MQTT_connect(); 49 | 50 | tm = millis(); 51 | if( tm > pub_next_tm ){ 52 | pub_next_tm = tm + pub_to; 53 | Serial.print(F("\nSending photocell val ")); 54 | Serial.print(x); 55 | Serial.print("..."); 56 | if (! photocell.publish(x++)) { 57 | Serial.println(F("Failed")); 58 | } else { 59 | Serial.println(F("OK!")); 60 | } 61 | } 62 | } 63 | 64 | void MQTT_connect() { 65 | int8_t ret; 66 | 67 | if (mqtt.connected()) { 68 | return; 69 | } 70 | 71 | Serial.print("Connecting to MQTT... "); 72 | 73 | uint8_t retries = 3; 74 | while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected 75 | Serial.println(mqtt.connectErrorString(ret)); 76 | Serial.println("Retrying MQTT connection in 5 seconds..."); 77 | mqtt.disconnect(); 78 | delay(5000); // wait 5 seconds 79 | retries--; 80 | if (retries == 0) { 81 | // basically die and wait for WDT to reset me 82 | while (1); 83 | } 84 | } 85 | Serial.println("MQTT Connected!"); 86 | } 87 | -------------------------------------------------------------------------------- /sketches/IOT.Matrix_8x8_article/nodemcu-matrix/nodemcu-matrix.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | Max72xxPanel matrix = Max72xxPanel(D8, 4, 1); 6 | 7 | unsigned long ticker_next; 8 | String tape = "Hello from RobotClass!"; 9 | int spacer = 1; 10 | int width = 5 + spacer; 11 | 12 | void setup(void){ 13 | matrix.setIntensity(7); 14 | } 15 | 16 | void handleTicker(){ 17 | for ( int i = 0 ; i < width * tape.length() + matrix.width() - 1 - spacer; i++ ) { 18 | matrix.fillScreen(LOW); 19 | 20 | int letter = i / width; 21 | int x = (matrix.width() - 1) - i % width; 22 | int y = (matrix.height() - 8) / 2; 23 | 24 | while ( x + width - spacer >= 0 && letter >= 0 ) { 25 | if ( letter < tape.length() ) { 26 | matrix.drawChar(x, y, tape[letter], HIGH, LOW, 1); 27 | } 28 | 29 | letter--; 30 | x -= width; 31 | } 32 | 33 | matrix.write(); // Send bitmap to display 34 | delay(50); 35 | } 36 | } 37 | 38 | void loop(void){ 39 | handleTicker(); 40 | } 41 | -------------------------------------------------------------------------------- /sketches/Interrupt_lesson/ardu-irq-rpm/ardu-irq-rpm.ino: -------------------------------------------------------------------------------- 1 | const byte interruptPin = 2; 2 | unsigned int rot = 0; 3 | unsigned long int tm; 4 | unsigned long int spd = 0; 5 | unsigned int dt = 0; 6 | 7 | 8 | void detect() { 9 | rot++; 10 | dt = millis() - tm; 11 | if( dt >= 100 ){ 12 | spd = rot*60000/dt; 13 | rot = 0; 14 | tm = millis(); 15 | } 16 | } 17 | 18 | void setup() { 19 | Serial.begin(9600); 20 | 21 | pinMode(interruptPin, INPUT_PULLUP); 22 | attachInterrupt(digitalPinToInterrupt(interruptPin), detect, RISING); 23 | 24 | tm = millis(); 25 | } 26 | 27 | void loop() { 28 | Serial.println(spd); 29 | delay(100); 30 | } 31 | -------------------------------------------------------------------------------- /sketches/Interrupt_lesson/ardu-irq-serial/ardu-irq-serial.ino: -------------------------------------------------------------------------------- 1 | const byte interruptPin = 2; 2 | long int rot = 0; 3 | 4 | void detect() { 5 | rot++; 6 | } 7 | 8 | void setup() { 9 | Serial.begin(9600); 10 | 11 | pinMode(interruptPin, INPUT_PULLUP); 12 | attachInterrupt(digitalPinToInterrupt(interruptPin), detect, RISING); 13 | } 14 | 15 | void loop() { 16 | Serial.println(rot); 17 | delay(100); 18 | } 19 | -------------------------------------------------------------------------------- /sketches/LED.7segment_595_lesson/seg_led_reg/seg_led_reg.ino: -------------------------------------------------------------------------------- 1 | const int data_pin = 2; 2 | const int sh_pin = 3; 3 | const int st_pin = 4; 4 | 5 | int bt = 0; 6 | 7 | void shift(byte v){ 8 | for(int i=0; i<8; i++){ 9 | digitalWrite(sh_pin, LOW); 10 | digitalWrite(data_pin, v & (1 << i )); 11 | digitalWrite(sh_pin, HIGH); 12 | } 13 | digitalWrite(st_pin, HIGH); 14 | digitalWrite(st_pin, LOW); 15 | } 16 | 17 | void setup() { 18 | pinMode(data_pin, OUTPUT); 19 | pinMode(sh_pin, OUTPUT); 20 | pinMode(st_pin, OUTPUT); 21 | } 22 | 23 | void loop() { 24 | shift(1< next_sec ){ 76 | next_sec = tm + to_sec; 77 | counter++; 78 | if( counter == 1000 ) 79 | counter = 0; 80 | } 81 | 82 | tm = millis(); 83 | if( tm > next_flick ){ 84 | next_flick = tm + to_flick; 85 | digit++; 86 | if( digit == 3 ) 87 | digit = 0; 88 | setDigit( digit, 125 ); 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /sketches/LED.Dynamic_lesson/dyn_3digit_static/dyn_3digit_static.ino: -------------------------------------------------------------------------------- 1 | const byte digit_pins[3] = {5,6,7}; 2 | const byte data_pin = 2; 3 | const byte sh_pin = 3; 4 | const byte st_pin = 4; 5 | 6 | unsigned long tm, next_flick; 7 | const unsigned int to_flick = 1; 8 | 9 | byte digit = 0; 10 | unsigned int counter = 125; 11 | 12 | const byte digits[10] = { 13 | B11101110, 14 | B10000010, 15 | B11011100, 16 | B11010110, 17 | B10110010, 18 | B01110110, 19 | B01111110, 20 | B11000010, 21 | B11111110, 22 | B11110110 23 | }; 24 | 25 | void fill( byte d ){ 26 | for(char i=0; i<8; i++){ 27 | digitalWrite(sh_pin, LOW); 28 | digitalWrite(data_pin, digits[d] & (1< next_flick ){ 73 | next_flick = tm + to_flick; 74 | digit++; 75 | if( digit == 3 ) 76 | digit = 0; 77 | setDigit( digit, counter ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /sketches/LED.Led_Matrix_595_lesson/led-matrix-8x8-max7219-char/led-matrix-8x8-max7219-char.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int pinCS = 9; 6 | int numberOfHorizontalDisplays = 1; 7 | int numberOfVerticalDisplays = 1; 8 | 9 | Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); 10 | 11 | String tape = "HELLO WORLD!"; 12 | int wait = 20; 13 | 14 | void setup() { 15 | matrix.setIntensity(7); // яркость от 0 до 15 16 | } 17 | 18 | void loop() { 19 | for ( int i = 0 ; i < tape.length(); i++ ) { 20 | matrix.fillScreen(LOW); 21 | matrix.drawChar(x, y, tape[letter], HIGH, LOW, 1); 22 | matrix.write(); 23 | 24 | delay(wait); 25 | } 26 | } 27 | 28 | -------------------------------------------------------------------------------- /sketches/LED.Led_Matrix_595_lesson/led-matrix-8x8-max7219-pixel/led-matrix-8x8-max7219-pixel.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int pinCS = 9; 6 | int numberOfHorizontalDisplays = 1; // количество матриц по горизонтали 7 | int numberOfVerticalDisplays = 1; // количество матриц по вертикали 8 | 9 | Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); 10 | 11 | int wait = 20; // время между 12 | 13 | int x,y; 14 | 15 | void setup() { 16 | matrix.setIntensity(4); // яркость от 0 до 15 17 | } 18 | 19 | void loop() { 20 | matrix.drawPixel(x, y, LOW); // гасим пиксел с текущими координатами 21 | x++; 22 | if( x==8 ){ 23 | x = 0; 24 | y++; 25 | if( y==8 ){ 26 | y = 0; 27 | } 28 | } 29 | 30 | matrix.drawPixel(x, y, HIGH); // зажигаем пиксел с новыми координатами 31 | matrix.write(); // вывод всех пикселей на матрицу 32 | 33 | delay(wait); 34 | } 35 | -------------------------------------------------------------------------------- /sketches/LED.Led_Matrix_595_lesson/led-matrix-8x8-max7219-smile/led-matrix-8x8-max7219-smile.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int pinCS = 10; 6 | int numberOfHorizontalDisplays = 4; 7 | int numberOfVerticalDisplays = 1; 8 | 9 | Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); 10 | 11 | const byte data[8] = { 12 | 0b00111100, 13 | 0b01000010, 14 | 0b10100101, 15 | 0b10000001, 16 | 0b10100101, 17 | 0b10011001, 18 | 0b01000010, 19 | 0b00111100 20 | }; 21 | 22 | void setup() { 23 | matrix.setIntensity(7); // уровень яркости от 0 до 15 24 | 25 | matrix.fillScreen(LOW); // очистка матрицы 26 | for ( int y = 0; y < 8; y++ ) { 27 | for ( int x = 0; x < 8; x++ ) { 28 | matrix.drawPixel(x, y, data[y] & (1< next_flick ){ 68 | next_flick = tm + to_flick; 69 | line++; 70 | if( line == 8 ) 71 | line = 0; 72 | // включаем строку № line 73 | fill( ~(1<<(7-line)) ); 74 | // зажигаем точки в строке № line 75 | fill( data[frame][7-line] ); 76 | latchOn(); 77 | } 78 | 79 | tm = micros(); 80 | if( tm > next_switch ){ 81 | next_switch = tm + to_switch; 82 | frame = !frame; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /sketches/LED.Led_Matrix_595_lesson/led-matrix-8x8-smile/led-matrix-8x8-smile.ino: -------------------------------------------------------------------------------- 1 | const byte data_pin = PD2; 2 | const byte st_pin = PD3; 3 | const byte sh_pin = PD4; 4 | const byte oe_pin = PD5; 5 | 6 | unsigned long tm, next_flick; 7 | const unsigned int to_flick = 500; 8 | 9 | byte line = 0; 10 | 11 | const byte data[8] = { 12 | 0b00111100, 13 | 0b01000010, 14 | 0b10100101, 15 | 0b10000001, 16 | 0b10100101, 17 | 0b10011001, 18 | 0b01000010, 19 | 0b00111100 20 | }; 21 | 22 | void latchOn(){ 23 | digitalWriteFast(st_pin, HIGH); 24 | digitalWriteFast(st_pin, LOW); 25 | } 26 | 27 | void fill( byte d ){ 28 | for(char i=0; i<8; i++){ 29 | digitalWriteFast(sh_pin, LOW); 30 | digitalWriteFast(data_pin, d & (1< next_flick ){ 57 | next_flick = tm + to_flick; 58 | line++; 59 | if( line == 8 ) 60 | line = 0; 61 | // включаем строку № line 62 | fill( ~(1<<(7-line)) ); 63 | // зажигаем точки в строке № line 64 | fill( data[line] ); 65 | latchOn(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sketches/LED.RGB_lesson/ardu-rgb-cycle3/ardu-rgb-cycle3.ino: -------------------------------------------------------------------------------- 1 | const byte rPin = 3; 2 | const byte gPin = 5; 3 | const byte bPin = 6; 4 | 5 | void setup() { 6 | pinMode( rPin, OUTPUT ); 7 | pinMode( gPin, OUTPUT ); 8 | pinMode( bPin, OUTPUT ); 9 | } 10 | 11 | void loop() { 12 | digitalWrite( bPin, LOW ); 13 | digitalWrite( rPin, HIGH ); 14 | delay( 1000 ); 15 | digitalWrite( rPin, LOW ); 16 | digitalWrite( gPin, HIGH ); 17 | delay( 1000 ); 18 | digitalWrite( gPin, LOW ); 19 | digitalWrite( bPin, HIGH ); 20 | delay( 1000 ); 21 | } 22 | -------------------------------------------------------------------------------- /sketches/LED.RGB_lesson/ardu-rgb-cycle3m/ardu-rgb-cycle3m.ino: -------------------------------------------------------------------------------- 1 | const byte rgbPins[3] = {3,5,6}; 2 | 3 | void setup() { 4 | for( byte i=0; i<3; i++ ) 5 | pinMode( rgbPins[i], OUTPUT ); 6 | } 7 | 8 | void loop() { 9 | digitalWrite( rgbPins[2], LOW ); 10 | digitalWrite( rgbPins[0], HIGH ); 11 | delay( 500 ); 12 | digitalWrite( rgbPins[0], LOW ); 13 | digitalWrite( rgbPins[1], HIGH ); 14 | delay( 500 ); 15 | digitalWrite( rgbPins[1], LOW ); 16 | digitalWrite( rgbPins[2], HIGH ); 17 | delay( 500 ); 18 | } 19 | -------------------------------------------------------------------------------- /sketches/LED.RGB_lesson/ardu-rgb-rainbow/ardu-rgb-rainbow.ino: -------------------------------------------------------------------------------- 1 | const byte rgbPins[3] = {3,5,6}; 2 | const byte rainbow[6][3] = { 3 | {1,0,0}, 4 | {1,1,0}, 5 | {0,1,0}, 6 | {0,1,1}, 7 | {0,0,1}, 8 | {1,0,1}, 9 | }; 10 | 11 | void setup() { 12 | for( byte i=0; i<3; i++ ) 13 | pinMode( rgbPins[i], OUTPUT ); 14 | } 15 | 16 | void loop() { 17 | for( int i=0; i<6; i++ ){ 18 | for( int k=0; k<3; k++ ){ 19 | digitalWrite( rgbPins[k], rainbow[i][k] ); 20 | } 21 | delay( 1000 ); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sketches/LED.RGB_lesson/ardu-rgb/ardu-rgb.ino: -------------------------------------------------------------------------------- 1 | const byte rgbPins[3] = {3,5,6}; 2 | const byte dim = 1; 3 | 4 | void setup() { 5 | for(byte i=0; i<3; i++){ 6 | pinMode( rgbPins[i], OUTPUT ); 7 | } 8 | analogWrite(rgbPins[0], 255/dim); 9 | analogWrite(rgbPins[1], 0); 10 | analogWrite(rgbPins[2], 0); 11 | } 12 | 13 | void loop() { 14 | for(int i=255; i>=0; i--){ 15 | analogWrite( rgbPins[0], i/dim ); 16 | analogWrite( rgbPins[1], (255-i)/dim ); 17 | delay(10); 18 | } 19 | for(int i=255; i>=0; i--){ 20 | analogWrite( rgbPins[1], i/dim ); 21 | analogWrite( rgbPins[2], (255-i)/dim ); 22 | delay(10); 23 | } 24 | for(int i=255; i>=0; i--){ 25 | analogWrite( rgbPins[2], i/dim ); 26 | analogWrite( rgbPins[0], (255-i)/dim ); 27 | delay(10); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sketches/LED.ROC.Led_Matrix_lesson/matrix8x8-basic-opt/matrix8x8-basic-opt.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | Эта библиотека разработана специально для модуля светодиодной матрицы 8x8 ROC 3 | 4 | ----> https://shop.robotclass.ru/index.php?route=product/product&product_id=733 5 | 6 | Данный модуль работает по интерфейсу I2C, используя два контакта SDA и SCL. 7 | Имеется возможность использовать разные адреса I2C. Для этого нужно разрезать 8 | или спаять специальные адресные перемычки на обратной стороне платы. 9 | Для модулей с двумя адресными пермычками можно выбрать один адрес из четырёх: 10 | 0x70, 0x71, 0x72 or 0x73. Для модулей с тремя адресными перемычками допустимы 11 | адреса с 0x70 по 0x77. 12 | 13 | RobotClass вкладывает много сил в создание уроков по основам электроники 14 | и программированию микроконтроллеров. Покупая наши продукты, вы помогаете 15 | нам создавать новые уроки и модули! 16 | 17 | Автор: Олег Евсегнеев, RobotClass. 18 | BSD license, all text above must be included in any redistribution 19 | ****************************************************/ 20 | 21 | #include 22 | #include "Adafruit_LEDBackpack.h" 23 | 24 | Adafruit_8x8matrix matrix = Adafruit_8x8matrix(); 25 | 26 | void setup() { 27 | matrix.begin(0x70); // устанавливаем адрес модуля 28 | delay(1000); // пауза 1 секунда, можно убрать 29 | matrix.clear(); // очищаем буфер матрицы 30 | // рисуем квадрат 31 | for(byte i=0; i<8; i++){ 32 | matrix.drawPixel(i, 0, 1); // верхняя линия 33 | matrix.drawPixel(i, 7, 1); // нижняя линия 34 | matrix.drawPixel(0, i, 1); // левая линия 35 | matrix.drawPixel(7, i, 1); // правая линия 36 | } 37 | // выводим буфер данных на матрицу 38 | matrix.writeDisplay(); 39 | } 40 | 41 | void loop() { 42 | } 43 | -------------------------------------------------------------------------------- /sketches/LED.ROC.Led_Matrix_lesson/matrix8x8-basic/matrix8x8-basic.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | Эта библиотека разработана специально для модуля светодиодной матрицы 8x8 ROC 3 | 4 | ----> https://shop.robotclass.ru/index.php?route=product/product&product_id=733 5 | 6 | Данный модуль работает по интерфейсу I2C, используя два контакта SDA и SCL. 7 | Имеется возможность использовать разные адреса I2C. Для этого нужно разрезать 8 | или спаять специальные адресные перемычки на обратной стороне платы. 9 | Для модулей с двумя адресными пермычками можно выбрать один адрес из четырёх: 10 | 0x70, 0x71, 0x72 or 0x73. Для модулей с тремя адресными перемычками допустимы 11 | адреса с 0x70 по 0x77. 12 | 13 | RobotClass вкладывает много сил в создание уроков по основам электроники 14 | и программированию микроконтроллеров. Покупая наши продукты, вы помогаете 15 | нам создавать новые уроки и модули! 16 | 17 | Автор: Олег Евсегнеев, RobotClass. 18 | BSD license, all text above must be included in any redistribution 19 | ****************************************************/ 20 | 21 | #include 22 | #include "Adafruit_LEDBackpack.h" 23 | 24 | Adafruit_8x8matrix matrix = Adafruit_8x8matrix(); 25 | 26 | void setup() { 27 | matrix.begin(0x70); // устанавливаем адрес модуля 28 | delay(1000); // пауза 1 секунда, можно убрать 29 | matrix.clear(); // очищаем буфер матрицы 30 | // горизонтальная линия сверху 31 | for(byte x=0; x<8; x++){ 32 | matrix.drawPixel(x, 0, 1); 33 | } 34 | // горизонтальная линия снизу 35 | for(byte x=0; x<8; x++){ 36 | matrix.drawPixel(x, 7, 1); 37 | } 38 | // вертикальная линия слева 39 | for(byte y=0; y<8; y++){ 40 | matrix.drawPixel(0, y, 1); 41 | } 42 | // вертикальная линия справа 43 | for(byte y=0; y<8; y++){ 44 | matrix.drawPixel(7, y, 1); 45 | } 46 | // выводим буфер данных на матрицу 47 | matrix.writeDisplay(); 48 | } 49 | 50 | void loop() { 51 | } 52 | -------------------------------------------------------------------------------- /sketches/LED.ROC.Led_Matrix_lesson/matrix8x8-count/matrix8x8-count.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | Эта библиотека разработана специально для модуля светодиодной матрицы 8x8 ROC 3 | 4 | ----> https://shop.robotclass.ru/index.php?route=product/product&product_id=733 5 | 6 | Данный модуль работает по интерфейсу I2C, используя два контакта SDA и SCL. 7 | Имеется возможность использовать разные адреса I2C. Для этого нужно разрезать 8 | или спаять специальные адресные перемычки на обратной стороне платы. 9 | Для модулей с двумя адресными пермычками можно выбрать один адрес из четырёх: 10 | 0x70, 0x71, 0x72 or 0x73. Для модулей с тремя адресными перемычками допустимы 11 | адреса с 0x70 по 0x77. 12 | 13 | RobotClass вкладывает много сил в создание уроков по основам электроники 14 | и программированию микроконтроллеров. Покупая наши продукты, вы помогаете 15 | нам создавать новые уроки и модули! 16 | 17 | Автор: Олег Евсегнеев, RobotClass. 18 | BSD license, all text above must be included in any redistribution 19 | ****************************************************/ 20 | 21 | #include 22 | #include "Adafruit_GFX.h" 23 | #include "Adafruit_LEDBackpack.h" 24 | 25 | Adafruit_8x8matrix matrix = Adafruit_8x8matrix(); 26 | 27 | void setup() { 28 | matrix.begin(0x70); // устанавливаем адрес модуля 29 | delay(1000); // пауза 1 секунда, можно убрать 30 | } 31 | 32 | void loop() { 33 | // запускаем цикл от символа '9' до символа '0' 34 | // что эквивалентно перебору чисела от 57 до 48 35 | for( char c='9'; c>='0'; c--){ 36 | matrix.clear(); // очищаем буфер матрицы 37 | matrix.drawChar(0, 0, c, 1, 0, 1); 38 | matrix.writeDisplay(); // выводим буфер в матрицу 39 | delay(1000); // пауза 1 секунда 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sketches/LED.ROC.Led_Matrix_lesson/matrix8x8-heart/matrix8x8-heart.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | Эта библиотека разработана специально для модуля светодиодной матрицы 8x8 ROC 3 | 4 | ----> https://shop.robotclass.ru/index.php?route=product/product&product_id=733 5 | 6 | Данный модуль работает по интерфейсу I2C, используя два контакта SDA и SCL. 7 | Имеется возможность использовать разные адреса I2C. Для этого нужно разрезать 8 | или спаять специальные адресные перемычки на обратной стороне платы. 9 | Для модулей с двумя адресными пермычками можно выбрать один адрес из четырёх: 10 | 0x70, 0x71, 0x72 or 0x73. Для модулей с тремя адресными перемычками допустимы 11 | адреса с 0x70 по 0x77. 12 | 13 | RobotClass вкладывает много сил в создание уроков по основам электроники 14 | и программированию микроконтроллеров. Покупая наши продукты, вы помогаете 15 | нам создавать новые уроки и модули! 16 | 17 | Автор: Олег Евсегнеев, RobotClass. 18 | BSD license, all text above must be included in any redistribution 19 | ****************************************************/ 20 | 21 | #include 22 | #include 23 | #include "Adafruit_LEDBackpack.h" 24 | 25 | Adafruit_8x8matrix matrix = Adafruit_8x8matrix(); 26 | 27 | // объявляем двумерный массив с картинками 28 | static const uint8_t PROGMEM frames[2][8] = { 29 | { B00000000, 30 | B01100110, 31 | B11111111, 32 | B11111111, 33 | B01111110, 34 | B00111100, 35 | B00011000, 36 | B00000000 }, 37 | { B00000000, 38 | B00100100, 39 | B01111110, 40 | B01111110, 41 | B00111100, 42 | B00011000, 43 | B00000000, 44 | B00000000 } 45 | }; 46 | 47 | void setup() { 48 | matrix.begin(0x70); // устанавливаем адрес модуля 49 | } 50 | 51 | void loop() { 52 | matrix.clear(); // очищаем буфер матрицы 53 | // заполняем буфер матрицы первой картинкой 54 | matrix.drawBitmap(0, 0, frames[0], 8, 8, 1); 55 | matrix.writeDisplay(); // выводим буфер в матрицу 56 | delay(200); // пауза 200 мс 57 | matrix.clear(); // очищаем буфер матрицы 58 | // заполняем буфер матрицы второй картинкой 59 | matrix.drawBitmap(0, 0, frames[1], 8, 8, 1); 60 | matrix.writeDisplay(); // выводим буфер в матрицу 61 | delay(500); // пауза 200 мс 62 | } 63 | -------------------------------------------------------------------------------- /sketches/LED.ROC.Led_Matrix_lesson/matrix8x8-scan/matrix8x8-scan.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for our I2C LED Backpacks 3 | 4 | Designed specifically to work with the Adafruit LED Matrix backpacks 5 | ----> http://www.adafruit.com/products/872 6 | ----> http://www.adafruit.com/products/871 7 | ----> http://www.adafruit.com/products/870 8 | 9 | These displays use I2C to communicate, 2 pins are required to 10 | interface. There are multiple selectable I2C addresses. For backpacks 11 | with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks 12 | with 3 Address Select pins: 0x70 thru 0x77 13 | 14 | Adafruit invests time and resources providing this open source code, 15 | please support Adafruit and open-source hardware by purchasing 16 | products from Adafruit! 17 | 18 | Written by Limor Fried/Ladyada for Adafruit Industries. 19 | BSD license, all text above must be included in any redistribution 20 | ****************************************************/ 21 | 22 | #include 23 | #include 24 | #include "Adafruit_LEDBackpack.h" 25 | 26 | Adafruit_8x8matrix matrix = Adafruit_8x8matrix(); 27 | 28 | static const uint8_t PROGMEM box[] = { 29 | B00111100, 30 | B01000010, 31 | B10100101, 32 | B10000001, 33 | B10100101, 34 | B10011001, 35 | B01000010, 36 | B00111100 37 | }; 38 | 39 | void setup() { 40 | Serial.begin(9600); 41 | Serial.println("8x8 LED Matrix Test"); 42 | 43 | matrix.begin(0x70); // pass in the address 44 | 45 | matrix.clear(); 46 | matrix.drawBitmap(0, 0, box, 8, 8, LED_ON); 47 | matrix.writeDisplay(); 48 | delay(2000); 49 | matrix.clear(); 50 | } 51 | 52 | void loop() { 53 | matrix.clear(); 54 | for(byte x=0; x<8; x++){ 55 | if(x>0) 56 | matrix.drawLine(x-1, 0, x-1, 7, 0); 57 | matrix.drawLine(x, 0, x, 7, 1); 58 | matrix.writeDisplay(); 59 | delay(100); 60 | } 61 | matrix.drawLine(7, 0, 7, 7, 0); 62 | for(byte y=0; y<8; y++){ 63 | if(y>0) 64 | matrix.drawLine(0, y-1, 7, y-1, 0); 65 | matrix.drawLine(0, y, 7, y, 1); 66 | matrix.writeDisplay(); 67 | delay(100); 68 | } 69 | matrix.drawLine(0, 7, 7, 7, 0); 70 | } 71 | -------------------------------------------------------------------------------- /sketches/LED.ROC.Led_Matrix_lesson/matrix8x8/matrix8x8.ino: -------------------------------------------------------------------------------- 1 | /*************************************************** 2 | This is a library for our I2C LED Backpacks 3 | 4 | Designed specifically to work with the Adafruit LED Matrix backpacks 5 | ----> http://www.adafruit.com/products/872 6 | ----> http://www.adafruit.com/products/871 7 | ----> http://www.adafruit.com/products/870 8 | 9 | These displays use I2C to communicate, 2 pins are required to 10 | interface. There are multiple selectable I2C addresses. For backpacks 11 | with 2 Address Select pins: 0x70, 0x71, 0x72 or 0x73. For backpacks 12 | with 3 Address Select pins: 0x70 thru 0x77 13 | 14 | Adafruit invests time and resources providing this open source code, 15 | please support Adafruit and open-source hardware by purchasing 16 | products from Adafruit! 17 | 18 | Written by Limor Fried/Ladyada for Adafruit Industries. 19 | BSD license, all text above must be included in any redistribution 20 | ****************************************************/ 21 | 22 | #include 23 | #include 24 | #include "Adafruit_LEDBackpack.h" 25 | 26 | Adafruit_8x8matrix matrix = Adafruit_8x8matrix(); 27 | 28 | static const uint8_t PROGMEM box[] = { 29 | B00111100, 30 | B01000010, 31 | B10100101, 32 | B10000001, 33 | B10100101, 34 | B10011001, 35 | B01000010, 36 | B00111100 37 | }; 38 | 39 | void setup() { 40 | Serial.begin(9600); 41 | Serial.println("8x8 LED Matrix Test"); 42 | 43 | matrix.begin(0x70); // pass in the address 44 | 45 | matrix.clear(); 46 | matrix.drawBitmap(0, 0, box, 8, 8, LED_ON); 47 | matrix.writeDisplay(); 48 | delay(2000); 49 | matrix.clear(); 50 | } 51 | 52 | void loop() { 53 | matrix.clear(); 54 | for(byte x=0; x<64; x++){ 55 | matrix.drawPixel(x % 8, x / 8, 1); 56 | matrix.writeDisplay(); 57 | delay(100); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sketches/LED.TM1637_article/TM1637_1234/TM1637_1234.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #define CLK 2 4 | #define DIO 3 5 | 6 | TM1637Display display(CLK, DIO); 7 | 8 | void setup(){ 9 | display.setBrightness(0x0f); 10 | } 11 | 12 | void loop(){ 13 | display.showNumberDec(12, false, 2, 0); 14 | display.showNumberDec(34, false, 2, 2); 15 | while(100); 16 | } 17 | -------------------------------------------------------------------------------- /sketches/LED.TM1637_article/TM1637_Alarm/TM1637_Alarm.ino: -------------------------------------------------------------------------------- 1 | //#include 2 | #include 3 | #include 4 | RtcDS3231 Rtc(Wire); 5 | 6 | #define ledPin 13 7 | 8 | #define RtcSquareWavePin 2 9 | #define RtcSquareWaveInterrupt 0 10 | 11 | volatile bool interuptFlag = false; 12 | bool ledFlag = false; 13 | 14 | void InteruptServiceRoutine(){ 15 | interuptFlag = true; 16 | } 17 | 18 | void blink(){ 19 | digitalWrite(ledPin, ledFlag); 20 | ledFlag = !ledFlag; 21 | } 22 | 23 | void setup(){ 24 | Serial.begin(9600); 25 | pinMode(RtcSquareWavePin, INPUT); 26 | pinMode(ledPin, OUTPUT); 27 | 28 | Rtc.Begin(); 29 | RtcDateTime compiled = RtcDateTime(2019,5,22,15,30,0); 30 | 31 | if (!Rtc.IsDateTimeValid()) { 32 | Serial.println("RTC lost confidence in the DateTime!"); 33 | Rtc.SetDateTime(compiled); 34 | } 35 | 36 | if (!Rtc.GetIsRunning()){ 37 | Serial.println("RTC was not actively running, starting now"); 38 | Rtc.SetIsRunning(true); 39 | } 40 | 41 | Rtc.Enable32kHzPin(false); 42 | Rtc.SetSquareWavePin(DS3231SquareWavePin_ModeAlarmBoth); 43 | 44 | RtcDateTime alarmTime = RtcDateTime(2019,5,22,15,38,0); 45 | DS3231AlarmOne alarm1( 46 | alarmTime.Day(), 47 | alarmTime.Hour(), 48 | alarmTime.Minute(), 49 | alarmTime.Second(), 50 | DS3231AlarmOneControl_HoursMinutesSecondsMatch); 51 | Rtc.SetAlarmOne(alarm1); 52 | 53 | // throw away any old alarm state before we ran 54 | Rtc.LatchAlarmsTriggeredFlags(); 55 | 56 | // setup external interupt 57 | attachInterrupt(RtcSquareWaveInterrupt, InteruptServiceRoutine, FALLING); 58 | } 59 | 60 | void loop(){ 61 | if(interuptFlag){ 62 | Serial.println("alarm!"); 63 | interuptFlag = false; 64 | } 65 | RtcDateTime now = Rtc.GetDateTime(); 66 | Serial.print(now.Hour()); 67 | Serial.print(":"); 68 | Serial.print(now.Minute()); 69 | Serial.print(":"); 70 | Serial.println(now.Second()); 71 | 72 | blink(); 73 | delay(1000); 74 | } 75 | -------------------------------------------------------------------------------- /sketches/LED.TM1637_article/TM1637_Clock/TM1637_Clock.ino: -------------------------------------------------------------------------------- 1 | //#include 2 | #include 3 | #include "RTClib.h" 4 | #include 5 | 6 | #define CLK 2 7 | #define DIO 3 8 | 9 | TM1637Display display(CLK, DIO); 10 | RTC_DS3231 rtc; 11 | 12 | byte tick = 0; 13 | 14 | void setup(){ 15 | display.setBrightness(0x0f); 16 | rtc.begin(); 17 | } 18 | 19 | void loop(){ 20 | DateTime now = rtc.now(); 21 | 22 | if( tick ) 23 | display.showNumberDecEx(now.hour(), (0x80 >> 3), true, 2, 0); 24 | else 25 | display.showNumberDecEx(now.hour(), 0, true, 2, 0); 26 | display.showNumberDec(now.minute(), true, 2, 2); 27 | 28 | tick = !tick; 29 | delay(1000); 30 | } 31 | -------------------------------------------------------------------------------- /sketches/LED.WS2812_lesson/ws2812_test/ws2812_test.ino/ws2812_test.ino.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define PIN 6 4 | #define NUMPIXELS 4 5 | 6 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 7 | 8 | byte state = 0; 9 | 10 | void setup() { 11 | pixels.begin(); // This initializes the NeoPixel library. 12 | } 13 | 14 | void loop() { 15 | for(int v=0; v<255; v+=15){ 16 | pixels.clear(); 17 | if( state ){ 18 | pixels.setPixelColor(0, pixels.Color(v,0,255-v)); 19 | pixels.setPixelColor(2, pixels.Color(v,0,255-v)); 20 | } else { 21 | pixels.setPixelColor(1, pixels.Color(v,0,255-v)); 22 | pixels.setPixelColor(3, pixels.Color(v,0,255-v)); 23 | } 24 | state = !state; 25 | pixels.show(); 26 | delay(200); 27 | } 28 | for(int v=0; v<255; v+=15){ 29 | for(int i=0;i 2 | 3 | int gRxPin = 10; 4 | int gTxPin = 11; 5 | 6 | int b1, b2, dist; 7 | 8 | SoftwareSerial BTSerial(gRxPin, gTxPin); 9 | 10 | void setup() { 11 | BTSerial.begin(57600); 12 | Serial.begin(9600); 13 | delay(500); 14 | } 15 | 16 | void loop() { 17 | BTSerial.write(0x55); 18 | if (BTSerial.available()) { 19 | b1 = BTSerial.read(); 20 | b2 = BTSerial.read(); 21 | dist = (b1 << 8) + b2; 22 | Serial.println(dist); 23 | } 24 | delay(100); 25 | } 26 | -------------------------------------------------------------------------------- /sketches/Link.Bluetooth/hc05_pairing/hc05_pairing.ino: -------------------------------------------------------------------------------- 1 | /* 2 | By : Phillipe Cantin 3 | Desc.: Basic automatic connection between 2 HC-type bluetooth modules 4 | */ 5 | #include 6 | #include 7 | 8 | int gLedPin = 13; 9 | int gPowerPin = 12; 10 | int gKeyPin = 9; 11 | int gRxPin = 10; 12 | int gTxPin = 11; 13 | int gResetPin = 8; 14 | 15 | int gIsMaster = 1; 16 | 17 | SoftwareSerial BTSerial(gRxPin, gTxPin); 18 | 19 | void BtReset(void){ 20 | Serial.println("BtReset"); 21 | BTSerial.flush(); 22 | delay(500); 23 | 24 | //Method 1: Using the power 25 | //digitalWrite(gPowerPin, LOW); 26 | //delay(2000); 27 | //digitalWrite(gPowerPin, HIGH); 28 | 29 | //Method 2: Using the reset pin 30 | digitalWrite(gResetPin, LOW); 31 | delay(2000); 32 | digitalWrite(gResetPin, HIGH); 33 | 34 | delay(500); 35 | } 36 | 37 | void BtSetCmdMode(int i_cmdMode = 1){ 38 | Serial.print("BtSetCmdMode "); 39 | Serial.println(i_cmdMode); 40 | digitalWrite(gKeyPin, (1 == i_cmdMode)?HIGH:LOW); 41 | 42 | BtReset(); 43 | 44 | //BTSerial.begin((1 == i_cmdMode)?38400:57600);//57600 45 | BTSerial.begin(38400);//57600 46 | } 47 | 48 | void BtSetupRole(int i_isMaster = 1){ 49 | BTSerial.begin(38400); 50 | BtSetCmdMode(1); 51 | BTSerial.println("AT"); 52 | delay(1000); 53 | //BTSerial.println("AT+UART=57600,0,0"); 54 | //delay(1000); 55 | 56 | if(0 == i_isMaster){ 57 | BTSerial.println("AT+ROLE=0"); 58 | Serial.println("Set as Slave"); 59 | } else { 60 | BTSerial.println("AT+ORGL"); 61 | delay(500); 62 | BTSerial.println("AT+RMADD"); 63 | delay(500); 64 | BTSerial.println("AT+ROLE=1"); 65 | Serial.println("Set as Master"); 66 | } 67 | delay(1000); 68 | 69 | BtSetCmdMode(0); 70 | } 71 | 72 | void BtStartMaster(void){ 73 | BtSetCmdMode(1); 74 | 75 | BTSerial.println("AT+CMODE=1"); 76 | Serial.println("AT+CMODE"); 77 | delay(500); 78 | 79 | BTSerial.println("AT+INQM=0,5,5"); 80 | Serial.println("AT+INQM"); 81 | delay(500); 82 | 83 | BTSerial.println("AT+INIT"); 84 | Serial.println("AT command: AT+INIT"); 85 | delay(500); 86 | 87 | BTSerial.println("AT+INQ"); 88 | Serial.println("AT+INQ"); 89 | delay(500); 90 | 91 | //BTSerial.println("AT+LINK=13,3,191407"); 92 | //Serial.println("AT command: AT+LINK="); 93 | //delay(100); 94 | 95 | BtSetCmdMode(0); 96 | } 97 | 98 | void setup() 99 | { 100 | pinMode(gLedPin, OUTPUT); 101 | pinMode(gPowerPin, OUTPUT); 102 | digitalWrite(gPowerPin, LOW); 103 | pinMode(gKeyPin, OUTPUT); 104 | digitalWrite(gKeyPin, LOW); 105 | 106 | Serial.begin(9600); 107 | Serial.println("bt2bt HC module - version a"); 108 | 109 | if(1 == gIsMaster){ 110 | BtSetupRole(1); 111 | BtStartMaster(); 112 | }else{ 113 | BtSetupRole(0); 114 | } 115 | } 116 | 117 | void loop() 118 | { 119 | if (BTSerial.available()){ 120 | char tmpChar = BTSerial.read(); 121 | Serial.println(tmpChar); 122 | if(!gIsMaster && tmpChar == '1'){ 123 | digitalWrite(gLedPin, HIGH); 124 | } else if(tmpChar == '0'){ 125 | digitalWrite(gLedPin, LOW); 126 | } 127 | } 128 | 129 | if( gIsMaster ){ 130 | BTSerial.print("1"); 131 | delay(1000); 132 | BTSerial.print("0"); 133 | delay(1000); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /sketches/Link.HC-05_lesson/bt_dim/bt_dim.ino: -------------------------------------------------------------------------------- 1 | int led1pin = 3; 2 | 3 | void setup() { 4 | Serial.begin(9600); 5 | 6 | // настройка контактов 7 | pinMode(led1pin, OUTPUT); 8 | } 9 | 10 | void loop() { 11 | byte data; 12 | // есть во входном буфере есть данные 13 | if( Serial.available() > 0 ){ 14 | data = Serial.read(); // считываем один байт из буфера 15 | if( data >= 48 && data <= 57 ){ 16 | analogWrite(led1pin, 255*(data-48)/9); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /sketches/Link.HC-05_lesson/bt_led/bt_led.ino: -------------------------------------------------------------------------------- 1 | int led1pin = 2; 2 | int led2pin = 3; 3 | int led3pin = 4; 4 | int led4pin = 5; 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | 9 | // настройка контактов 10 | pinMode(led1pin, OUTPUT); 11 | pinMode(led2pin, OUTPUT); 12 | pinMode(led3pin, OUTPUT); 13 | pinMode(led4pin, OUTPUT); 14 | } 15 | 16 | void loop() { 17 | char data; 18 | // есть во входном буфере есть данные 19 | if( Serial.available() > 0 ){ 20 | data = Serial.read(); // считываем один байт из буфера 21 | switch(data){ 22 | case 'R':{ 23 | digitalWrite(led1pin, HIGH); 24 | break; 25 | } 26 | case 'L':{ 27 | digitalWrite(led2pin, HIGH); 28 | break; 29 | } 30 | case 'F':{ 31 | digitalWrite(led3pin, HIGH); 32 | break; 33 | } 34 | case 'B':{ 35 | digitalWrite(led4pin, HIGH); 36 | break; 37 | } 38 | default:{ 39 | digitalWrite(led1pin, LOW); 40 | digitalWrite(led2pin, LOW); 41 | digitalWrite(led3pin, LOW); 42 | digitalWrite(led4pin, LOW); 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sketches/Link.HC-05_lesson/bt_robot/bt_robot.ino: -------------------------------------------------------------------------------- 1 | int in1pin = 2; 2 | int in2pin = 4; 3 | int in3pin = 6; 4 | int in4pin = 7; 5 | 6 | // поворт направо 7 | void turnRight(){ 8 | digitalWrite(in1pin, HIGH); 9 | digitalWrite(in2pin, LOW); 10 | digitalWrite(in3pin, LOW); 11 | digitalWrite(in4pin, HIGH); 12 | } 13 | 14 | // поворт налево 15 | void turnLeft(){ 16 | digitalWrite(in1pin, LOW); 17 | digitalWrite(in2pin, HIGH); 18 | digitalWrite(in3pin, HIGH); 19 | digitalWrite(in4pin, LOW); 20 | } 21 | 22 | // движение назад 23 | void backward(){ 24 | digitalWrite(in1pin, HIGH); 25 | digitalWrite(in2pin, LOW); 26 | digitalWrite(in3pin, HIGH); 27 | digitalWrite(in4pin, LOW); 28 | } 29 | 30 | // движение вперед 31 | void forward(){ 32 | digitalWrite(in1pin, LOW); 33 | digitalWrite(in2pin, HIGH); 34 | digitalWrite(in3pin, LOW); 35 | digitalWrite(in4pin, HIGH); 36 | } 37 | 38 | // остановка 39 | void mstop(){ 40 | digitalWrite(in1pin, LOW); 41 | digitalWrite(in2pin, LOW); 42 | digitalWrite(in3pin, LOW); 43 | digitalWrite(in4pin, LOW); 44 | } 45 | 46 | void setup() { 47 | Serial.begin(9600); 48 | 49 | // настройка контактов 50 | pinMode(in1pin, OUTPUT); 51 | pinMode(in2pin, OUTPUT); 52 | pinMode(in3pin, OUTPUT); 53 | pinMode(in4pin, OUTPUT); 54 | } 55 | 56 | void loop() { 57 | byte data; 58 | // есть во входном буфере есть данные 59 | if( Serial.available() > 0 ){ 60 | data = Serial.read(); // считываем один байт из буфера 61 | switch(data){ 62 | case 'R':{ 63 | turnRight(); 64 | break; 65 | } 66 | case 'L':{ 67 | turnLeft(); 68 | break; 69 | } 70 | case 'F':{ 71 | forward(); 72 | break; 73 | } 74 | case 'B':{ 75 | backward(); 76 | break; 77 | } 78 | default:{ 79 | mstop(); 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /sketches/Link.IRLink_lesson/photo_analog/photo_analog.ino: -------------------------------------------------------------------------------- 1 | const byte photoPin = A0; 2 | 3 | void setup() { 4 | Serial.begin(9600); 5 | pinMode(photoPin, INPUT); 6 | } 7 | 8 | void loop() { 9 | int v = analogRead(photoPin); 10 | Serial.println(v); 11 | delay(100); 12 | } 13 | -------------------------------------------------------------------------------- /sketches/Link.IRLink_lesson/photo_basic/photo_basic.ino: -------------------------------------------------------------------------------- 1 | const byte photoPin = 3; 2 | 3 | void setup() { 4 | Serial.begin(9600); 5 | pinMode(photoPin, INPUT); 6 | } 7 | 8 | void loop() { 9 | byte v = digitalRead(photoPin); 10 | if(!v){ 11 | Serial.println("received"); 12 | } else { 13 | Serial.println("-"); 14 | } 15 | delay(100); 16 | } 17 | -------------------------------------------------------------------------------- /sketches/Link.IRLink_lesson/photo_serial/photo_serial.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | SoftwareSerial Photo (10, 11, 1); 4 | 5 | void setup() { 6 | Serial.begin(9600); 7 | Photo.begin(4800); 8 | } 9 | 10 | void loop() { 11 | while( Photo.available() ){ 12 | char v = Photo.read(); 13 | Serial.write(v); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /sketches/Link.IRLink_lesson/photo_tr_basic/photo_tr_basic.ino: -------------------------------------------------------------------------------- 1 | const byte ledPin = 2; 2 | 3 | void setup() { 4 | pinMode(ledPin, OUTPUT); 5 | } 6 | 7 | void loop() { 8 | digitalWrite(ledPin, HIGH); 9 | delay(500); 10 | digitalWrite(ledPin, LOW); 11 | delay(500); 12 | } 13 | -------------------------------------------------------------------------------- /sketches/Link.IRLink_lesson/photo_tr_serial/photo_tr_serial.ino: -------------------------------------------------------------------------------- 1 | void setup() { 2 | Serial.begin(4800); 3 | } 4 | 5 | void loop() { 6 | Serial.println("ping"); 7 | delay(200); 8 | } 9 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrf24-receiver-lcd-to/nrf24-receiver-lcd-to.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 O. Evsegneev 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Пример передачи данных через радиомодуль nRF24L01 11 | * Приемник 12 | * 13 | * Example for sensor data transmitting with nRF24L01 radios. 14 | * Receiver 15 | */ 16 | #include 17 | #include 18 | #include "printf.h" 19 | 20 | LiquidCrystal_I2C lcd(0x27,16,2); 21 | SerialFlow rd(7,8); 22 | 23 | const unsigned long data_to = 1000; 24 | unsigned long tm, data_next; 25 | 26 | void setup(void){ 27 | Serial.begin(57600); 28 | printf_begin(); 29 | 30 | rd.setPacketFormat(2, 1, 0); 31 | rd.begin(0xF0F0F0F0D2LL,0xF0F0F0F0E1LL); 32 | 33 | lcd.init(); 34 | lcd.backlight(); 35 | rd.getHWInfo(); 36 | } 37 | 38 | void loop(void){ 39 | unsigned int v; 40 | tm = millis(); 41 | if( tm > data_next ){ 42 | data_next = tm + data_to; 43 | lcd.setCursor(0,0); 44 | lcd.print("ERROR"); 45 | } 46 | 47 | if( rd.receivePacket() ){ 48 | v = rd.getPacketValue(0); 49 | lcd.setCursor(0,0); 50 | lcd.print(v); 51 | lcd.print(" "); 52 | data_next = millis() + data_to; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrf24-receiver-lcd-to/printf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2011 J. Coliz 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * @file printf.h 11 | * 12 | * Setup necessary to direct stdout to the Arduino Serial library, which 13 | * enables 'printf' 14 | */ 15 | 16 | #ifndef __PRINTF_H__ 17 | #define __PRINTF_H__ 18 | 19 | #ifdef ARDUINO 20 | 21 | int serial_putc( char c, FILE * ) 22 | { 23 | Serial.write( c ); 24 | 25 | return c; 26 | } 27 | 28 | void printf_begin(void) 29 | { 30 | fdevopen( &serial_putc, 0 ); 31 | } 32 | 33 | #else 34 | #error This example is only for use on Arduino. 35 | #endif // ARDUINO 36 | 37 | #endif // __PRINTF_H__ 38 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrf24-receiver-lcd/nrf24-receiver-lcd.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 O. Evsegneev 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Пример передачи данных через радиомодуль nRF24L01 11 | * Приемник 12 | * 13 | * Example for sensor data transmitting with nRF24L01 radios. 14 | * Receiver 15 | */ 16 | #include 17 | #include 18 | 19 | LiquidCrystal_I2C lcd(0x27,16,2); 20 | SerialFlow rd(7,8); 21 | 22 | const byte temp_pin = A0; 23 | const unsigned long data_to = 100; 24 | unsigned long tm, data_next; 25 | 26 | void setup(void){ 27 | pinMode( temp_pin, INPUT); 28 | 29 | rd.setPacketFormat(2, 1, 0); 30 | rd.begin(0xF0F0F0F0D2LL,0xF0F0F0F0E1LL); 31 | 32 | lcd.init(); 33 | lcd.backlight(); 34 | lcd.print("Hello"); 35 | } 36 | 37 | void loop(void){ 38 | unsigned int v; 39 | if( rd.receivePacket() ){ 40 | v = rd.getPacketValue(0); 41 | lcd.setCursor(0,0); 42 | lcd.print(v); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrf24-receiver/nrf24-receiver.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 O. Evsegneev 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example for sensor data transmitting with nRF24L01+ radios. 11 | */ 12 | #include 13 | 14 | SerialFlow rd(7,8); 15 | 16 | const unsigned long data_to = 100; 17 | unsigned long tm, data_next; 18 | 19 | void setup(void){ 20 | Serial.begin(57600); 21 | rd.setPacketFormat(2, 1, 0); 22 | rd.begin(0xF0F0F0F0D2LL,0xF0F0F0F0E1LL); 23 | } 24 | 25 | void loop(void){ 26 | unsigned int v; 27 | if( rd.receivePacket() ){ 28 | v = rd.getPacketValue(0); 29 | Serial.println(v); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrf24-transmitter-lcd/nrf24-transmitter-lcd.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 O. Evsegneev 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Пример передачи данных через радиомодуль nRF24L01 11 | * Передатчик 12 | * 13 | * Example for sensor data transmitting with nRF24L01+ radios. 14 | * Transmitter 15 | */ 16 | #include 17 | 18 | SerialFlow rd(7,8); 19 | 20 | const byte temp_pin = A0; 21 | const unsigned long data_to = 100; 22 | unsigned long tm, data_next; 23 | 24 | void setup(void){ 25 | pinMode( temp_pin, INPUT); 26 | 27 | rd.setPacketFormat(2, 1, 0); 28 | rd.begin(0xF0F0F0F0E1LL,0xF0F0F0F0D2LL); 29 | } 30 | 31 | void loop(void){ 32 | unsigned int v; 33 | tm = millis(); 34 | if( tm > data_next ){ 35 | data_next = tm + data_to; 36 | v = analogRead( temp_pin ); 37 | rd.setPacketValue( ( v/1023.0 )*5.0*1000/10 ); 38 | rd.sendPacket(); 39 | } 40 | } 41 | 42 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrf24-transmitter/nrf24-transmitter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 O. Evsegneev 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example for sensor data transmitting with nRF24L01+ radios. 11 | */ 12 | #include 13 | 14 | SerialFlow rd(7,8); 15 | 16 | const byte temp_pin = A0; 17 | const unsigned long data_to = 100; 18 | unsigned long tm, data_next; 19 | byte st = 0; 20 | 21 | void setup(void){ 22 | //pinMode( temp_pin, INPUT); 23 | pinMode( 13, OUTPUT); 24 | 25 | rd.setPacketFormat(2, 1, 0); 26 | rd.begin(0xF0F0F0F0E1LL,0xF0F0F0F0D2LL); 27 | } 28 | 29 | void loop(void){ 30 | unsigned int v; 31 | tm = millis(); 32 | if( tm > data_next ){ 33 | data_next = tm + data_to; 34 | //v = analogRead( temp_pin ); 35 | v = 556; 36 | rd.setPacketValue( v ); 37 | rd.sendPacket(); 38 | digitalWrite(13, st); 39 | st = !st; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrf24_pot_control/nrf24_pot_control.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | SerialFlow rd(7,8); 4 | 5 | const byte jx = A0; 6 | const byte jy = A1; 7 | 8 | const unsigned long data_to = 100; 9 | unsigned long tm, data_next; 10 | 11 | void setup(void){ 12 | rd.setPacketFormat(1, 1); 13 | rd.begin(0xF0F0F0F0E1LL,0xF0F0F0F0D2LL); 14 | 15 | pinMode(jx, INPUT); 16 | pinMode(jy, INPUT); 17 | } 18 | 19 | void loop(void){ 20 | tm = millis(); 21 | if( tm > data_next ){ 22 | data_next = tm + data_to; 23 | int x = analogRead(jx); 24 | int y = analogRead(jy); 25 | char v; 26 | if( x<100 ) 27 | v = 'B'; 28 | else if( x>900 ) 29 | v = 'F'; 30 | 31 | if( y<100 ) 32 | v = 'R'; 33 | else if( y>900 ) 34 | v = 'L'; 35 | 36 | rd.setPacketValue( v ); 37 | rd.sendPacket(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrflnatx/nrflnatx.ino: -------------------------------------------------------------------------------- 1 | void setup() 2 | { 3 | SPI_DIR = ( CE + SCK + CSN + MOSI); 4 | SPI_DIR &=~ ( IRQ + MISO); 5 | // attachInterrupt(1, _ISR, LOW);// interrupt enable 6 | Serial.begin(9600); 7 | init_io(); // Initialize IO port 8 | unsigned char status=SPI_Read(STATUS); 9 | Serial.print("status = "); 10 | Serial.println(status,HEX); // read the mode’s status register, the default value should be ‘E’ 11 | Serial.println("*******************TX_Mode Start****************************"); 12 | TX_Mode(); // set TX mode 13 | } 14 | void loop() 15 | { 16 | int k = 0; 17 | for(;;) 18 | { 19 | for(int i=0; i<32; i++) 20 | tx_buf[i] = k++; 21 | unsigned char status = SPI_Read(STATUS); // read register STATUS's value 22 | if(status&TX_DS) // if receive data ready (TX_DS) interrupt 23 | { 24 | SPI_RW_Reg(FLUSH_TX,0); 25 | SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH); // write playload to TX_FIFO 26 | } 27 | if(status&MAX_RT) // this is retransmit than SETUP_RETR 28 | { 29 | SPI_RW_Reg(FLUSH_TX,0); 30 | SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH); // disable standy-mode 31 | } 32 | SPI_RW_Reg(WRITE_REG+STATUS,status); // clear RX_DR or TX_DS or MAX_RT interrupt flag 33 | delay(1000); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrflnaty/nRF2401.h: -------------------------------------------------------------------------------- 1 | /* Memory Map */ 2 | #define NRF_CONFIG 0x00 3 | #define EN_AA 0x01 4 | #define EN_RXADDR 0x02 5 | #define SETUP_AW 0x03 6 | #define SETUP_RETR 0x04 7 | #define RF_CH 0x05 8 | #define RF_SETUP 0x06 9 | #define NRF_STATUS 0x07 10 | #define OBSERVE_TX 0x08 11 | #define CD 0x09 12 | #define RX_ADDR_P0 0x0A 13 | #define RX_ADDR_P1 0x0B 14 | #define RX_ADDR_P2 0x0C 15 | #define RX_ADDR_P3 0x0D 16 | #define RX_ADDR_P4 0x0E 17 | #define RX_ADDR_P5 0x0F 18 | #define TX_ADDR 0x10 19 | #define RX_PW_P0 0x11 20 | #define RX_PW_P1 0x12 21 | #define RX_PW_P2 0x13 22 | #define RX_PW_P3 0x14 23 | #define RX_PW_P4 0x15 24 | #define RX_PW_P5 0x16 25 | #define FIFO_STATUS 0x17 26 | #define DYNPD 0x1C 27 | #define FEATURE 0x1D 28 | 29 | #define ARD_4000US (0x0F<<4) 30 | 31 | #define AW_RERSERVED 0x0 32 | #define AW_3BYTES 0x1 33 | #define AW_4BYTES 0x2 34 | #define AW_5BYTES 0x3 35 | 36 | /* Bit Mnemonics */ 37 | #define MASK_RX_DR 6 38 | #define MASK_TX_DS 5 39 | #define MASK_MAX_RT 4 40 | #define EN_CRC 3 41 | #define CRCO 2 42 | #define PWR_UP 1 43 | #define PRIM_RX 0 44 | #define ENAA_P5 5 45 | #define ENAA_P4 4 46 | #define ENAA_P3 3 47 | #define ENAA_P2 2 48 | #define ENAA_P1 1 49 | #define ENAA_P0 0 50 | #define ERX_P5 5 51 | #define ERX_P4 4 52 | #define ERX_P3 3 53 | #define ERX_P2 2 54 | #define ERX_P1 1 55 | #define ERX_P0 0 56 | #define AW 0 57 | #define ARD 4 58 | #define ARC 0 59 | #define PLL_LOCK 4 60 | #define RF_DR 3 61 | #define RF_PWR 6 62 | #define RX_DR 6 63 | #define TX_DS 5 64 | #define MAX_RT 4 65 | #define RX_P_NO 1 66 | #define TX_FULL 0 67 | #define PLOS_CNT 4 68 | #define ARC_CNT 0 69 | #define TX_REUSE 6 70 | #define FIFO_FULL 5 71 | #define TX_EMPTY 4 72 | #define RX_FULL 1 73 | #define RX_EMPTY 0 74 | #define DPL_P5 5 75 | #define DPL_P4 4 76 | #define DPL_P3 3 77 | #define DPL_P2 2 78 | #define DPL_P1 1 79 | #define DPL_P0 0 80 | #define EN_DPL 2 81 | #define EN_ACK_PAY 1 82 | #define EN_DYN_ACK 0 83 | 84 | /* Instruction Mnemonics */ 85 | #define R_REGISTER 0x00 86 | #define W_REGISTER 0x20 87 | #define REGISTER_MASK 0x1F 88 | #define ACTIVATE 0x50 89 | #define R_RX_PL_WID 0x60 90 | #define R_RX_PAYLOAD 0x61 91 | #define W_TX_PAYLOAD 0xA0 92 | #define W_ACK_PAYLOAD 0xA8 93 | #define FLUSH_TX 0xE1 94 | #define FLUSH_RX 0xE2 95 | #define REUSE_TX_PL 0xE3 96 | #define NOP 0xFF 97 | 98 | /* Non-P omissions */ 99 | #define LNA_HCURR 0 100 | 101 | /* P model memory Map */ 102 | #define RPD 0x09 103 | #define W_TX_PAYLOAD_NO_ACK 0xB0 104 | 105 | /* P model bit Mnemonics */ 106 | #define RF_DR_LOW 5 107 | #define RF_DR_HIGH 3 108 | #define RF_PWR_LOW 1 109 | #define RF_PWR_HIGH 2 110 | 111 | 112 | -------------------------------------------------------------------------------- /sketches/Link.NRF24_lesson/nrflnaty/nrflnaty.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "nRF24L01.h" 3 | 4 | uint8_t ce_pin = 7; 5 | uint8_t csn_pin = 8; 6 | 7 | void writeSingleReg( uint8_t addr, uint8_t value ){ 8 | digitalWrite(csn_pin, LOW); 9 | SPI.transfer( W_REGISTER | (REGISTER_MASK & addr ) ); 10 | SPI.transfer( value ); 11 | digitalWrite(csn_pin, HIGH); 12 | } 13 | 14 | uint8_t readRegister(uint8_t reg){ 15 | uint8_t result; 16 | 17 | digitalWrite(csn_pin, LOW); 18 | SPI.transfer( R_REGISTER | ( REGISTER_MASK & reg ) ); 19 | result = SPI.transfer(0xff); 20 | digitalWrite(csn_pin, HIGH); 21 | 22 | return result; 23 | } 24 | 25 | void setup() { 26 | Serial.begin(115200); 27 | pinMode(ce_pin,OUTPUT); 28 | pinMode(csn_pin,OUTPUT); 29 | 30 | SPI.begin(); 31 | //digitalWrite(ce_pin, LOW); 32 | //digitalWrite(csn_pin, HIGH); 33 | //delay(5); 34 | //digitalWrite(ce_pin, HIGH); 35 | 36 | writeSingleReg( NRF_CONFIG, ( 1< 2 | 3 | RCSwitch mySwitch = RCSwitch(); 4 | 5 | void setup() { 6 | Serial.begin(9600); 7 | pinMode( 3, OUTPUT ); 8 | mySwitch.enableReceive(0); 9 | } 10 | 11 | void loop() { 12 | if (mySwitch.available()) { 13 | int value = mySwitch.getReceivedValue(); 14 | 15 | //if( value & B0001 ) 16 | // digitalWrite( 3, HIGH ); 17 | //if( value & B0010 ) 18 | // digitalWrite( 3, LOW ); 19 | 20 | Serial.println( value ); 21 | mySwitch.resetAvailable(); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sketches/Link.RF5-433/rf5tr/rf5tr.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | RCSwitch mySwitch = RCSwitch(); 4 | 5 | void setup() { 6 | mySwitch.enableTransmit(2); 7 | } 8 | 9 | void loop() { 10 | mySwitch.send(B0001, 4); 11 | delay(1000); 12 | mySwitch.send(B0010, 4); 13 | delay(1000); 14 | } 15 | -------------------------------------------------------------------------------- /sketches/Link.RS485_lesson/rs485_ping/rs485_ping.ino: -------------------------------------------------------------------------------- 1 | #define SerialTxControl 9 //RS485 управляющий контакт на arduino pin 10 2 | #define RS485Transmit HIGH 3 | #define RS485Receive LOW 4 | 5 | char buffer[100]; 6 | byte state = 0; 7 | 8 | unsigned long ping_next, t; 9 | unsigned int ping_to = 500; 10 | 11 | void setup(void) { 12 | Serial.begin(115200); 13 | pinMode(13, OUTPUT); 14 | pinMode(SerialTxControl, OUTPUT); 15 | digitalWrite(SerialTxControl, RS485Receive); 16 | } 17 | 18 | void loop(void) { 19 | int i=0; 20 | if( Serial.available() ){ 21 | delay(5); 22 | while( Serial.available() ){ 23 | buffer[i++] = Serial.read(); 24 | } 25 | if(i>0){ 26 | buffer[i++]='\0'; 27 | if( !strcmp(buffer, "pong") ){ 28 | digitalWrite(13, state); 29 | state = !state; 30 | } 31 | } 32 | } 33 | 34 | t = millis(); 35 | if( t>ping_next ){ 36 | ping_next = t + ping_to; 37 | digitalWrite(SerialTxControl, RS485Transmit); 38 | Serial.print("ping"); 39 | delay(5); 40 | digitalWrite(SerialTxControl, RS485Receive); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sketches/Link.RS485_lesson/rs485_pong/rs485_pong.ino: -------------------------------------------------------------------------------- 1 | #define SerialTxControl 9 //RS485 управляющий контакт на arduino pin 10 2 | #define RS485Transmit HIGH 3 | #define RS485Receive LOW 4 | 5 | char buffer[100]; 6 | byte state = 0; 7 | 8 | void setup(void) { 9 | Serial.begin(115200); 10 | pinMode(13, OUTPUT); 11 | pinMode(SerialTxControl, OUTPUT); 12 | digitalWrite(SerialTxControl, RS485Receive); 13 | } 14 | 15 | void loop(void) { 16 | int i=0; 17 | if( Serial.available() ){ 18 | delay(5); 19 | while( Serial.available() ){ 20 | buffer[i++] = Serial.read(); 21 | } 22 | if(i>0){ 23 | buffer[i++]='\0'; 24 | if( !strcmp(buffer, "ping") ){ 25 | digitalWrite(13, state); 26 | state = !state; 27 | digitalWrite(SerialTxControl, RS485Transmit); 28 | Serial.print("pong"); 29 | delay(10); 30 | digitalWrite(SerialTxControl, RS485Receive); 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sketches/Link.RS485_lesson/rs485_receive/rs485_receive.ino: -------------------------------------------------------------------------------- 1 | #define SerialTxControl 9 //RS485 управляющий контакт на arduino pin 10 2 | #define RS485Transmit HIGH 3 | #define RS485Receive LOW 4 | 5 | char buffer[100]; 6 | byte state = 0; 7 | 8 | void setup(void) { 9 | Serial.begin(9600); 10 | pinMode(13, OUTPUT); 11 | pinMode(SerialTxControl, OUTPUT); 12 | digitalWrite(SerialTxControl, RS485Receive); 13 | } 14 | 15 | void loop(void) { 16 | int i=0; 17 | if( Serial.available() ){ 18 | delay(5); 19 | while( Serial.available() ){ 20 | buffer[i++] = Serial.read(); 21 | } 22 | } 23 | if(i>0){ 24 | digitalWrite(13, state); 25 | state = !state; 26 | buffer[i++]='\0'; 27 | Serial.println(buffer); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sketches/Link.RS485_lesson/rs485_transmit/rs485_transmit.ino: -------------------------------------------------------------------------------- 1 | #define SerialTxControl 9 //RS485 управляющий контакт на arduino pin 10 2 | #define RS485Transmit HIGH 3 | #define RS485Receive LOW 4 | 5 | //char buffer[100]; 6 | 7 | void setup(void) { 8 | Serial.begin(9600); 9 | pinMode(SerialTxControl, OUTPUT); 10 | digitalWrite(SerialTxControl, RS485Transmit); 11 | } 12 | 13 | void loop(void) { 14 | //digitalWrite(SerialTxControl, RS485Transmit); 15 | Serial.print("ping"); 16 | //delay(100); 17 | //digitalWrite(SerialTxControl, RS485Receive); 18 | delay(500); 19 | } 20 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/SFlow_adxl345/SFlow_adxl345.ino: -------------------------------------------------------------------------------- 1 | static const byte PACKET_SIZE = 2; 2 | static const byte VALUE_SIZE = 2; 3 | static const boolean SEPARATE_VALUES = true; 4 | 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345); 12 | SerialFlow rd(&Serial); // RX, TX 13 | 14 | float acc_lpf[2] = {0,0}; 15 | 16 | void setup() { 17 | rd.setPacketFormat(VALUE_SIZE, PACKET_SIZE, SEPARATE_VALUES); 18 | rd.begin(115200); 19 | 20 | accel.begin(); 21 | accel.setRange(ADXL345_RANGE_2_G); 22 | } 23 | 24 | void loop() { 25 | sensors_event_t event; 26 | accel.getEvent(&event); 27 | 28 | acc_lpf[0] = acc_lpf[0]*0.98 + event.acceleration.x*0.02; 29 | acc_lpf[1] = acc_lpf[1]*0.98 + event.acceleration.y*0.02; 30 | 31 | rd.setPacketValue(int(acc_lpf[0]*10)); 32 | rd.setPacketValue(int(acc_lpf[1]*10)); 33 | rd.sendPacket(); 34 | 35 | delay(1); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/SFlow_position_test/SFlow_position_test.ino: -------------------------------------------------------------------------------- 1 | static const byte PACKET_SIZE = 2; 2 | static const byte VALUE_SIZE = 2; 3 | static const boolean SEPARATE_VALUES = true; 4 | 5 | #include 6 | #include 7 | 8 | SerialFlow rd(&Serial); // RX, TX 9 | 10 | const byte sz = 2; 11 | int x = 0; 12 | 13 | void setup() { 14 | rd.setPacketFormat(VALUE_SIZE, PACKET_SIZE, SEPARATE_VALUES); 15 | rd.begin(115200); 16 | } 17 | 18 | void loop() { 19 | rd.setPacketValue( x ); 20 | rd.setPacketValue( int( sin( x*3.14/180.0)*180) ); 21 | rd.sendPacket(); 22 | x++; 23 | if( x == 360 ) 24 | x = 0; 25 | delay(20); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/SFlow_simple_test/SFlow_simple_test.ino: -------------------------------------------------------------------------------- 1 | void setup() { 2 | Serial.begin(115200); 3 | pinMode(A0, INPUT); 4 | pinMode(3, OUTPUT); 5 | } 6 | 7 | void loop() { 8 | 9 | 10 | 11 | double t = (analogRead(A0)/1024.0)*255; 12 | 13 | if(t > 170) 14 | { 15 | analogWrite(3, 0); 16 | } 17 | else 18 | analogWrite(3, 255); 19 | 20 | Serial.write(byte(t)); 21 | delay(10); 22 | } 23 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/SFlow_vector_test/SFlow_vector_test.ino: -------------------------------------------------------------------------------- 1 | static const byte PACKET_SIZE = 128; 2 | static const byte VALUE_SIZE = 1; 3 | static const boolean SEPARATE_VALUES = false; 4 | 5 | #include 6 | #include 7 | 8 | SerialFlow rd(&Serial); // RX, TX 9 | 10 | const byte sz = 128; 11 | 12 | void setup() { 13 | rd.setPacketFormat(VALUE_SIZE, PACKET_SIZE, SEPARATE_VALUES); 14 | rd.begin(115200); 15 | } 16 | 17 | void loop() { 18 | for(int i=0; i 2 | 3 | ADXL345 accelerometer; 4 | 5 | Vector araw; 6 | 7 | void setup() { 8 | Serial.begin(115200); 9 | 10 | accelerometer.begin(); 11 | accelerometer.setRange(ADXL345_RANGE_16G); 12 | } 13 | 14 | void loop() { 15 | araw = accelerometer.readRaw(); 16 | Serial.println( araw.XAxis ); 17 | delay(20); 18 | } 19 | 20 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/sflow-receiver/sflow-receiver.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 O. Evsegneev 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example for sensor data receiving. 11 | */ 12 | #include 13 | 14 | const byte ledPin = 13; 15 | 16 | SerialFlow rd(&Serial); 17 | 18 | void setup(void){ 19 | pinMode(ledPin, OUTPUT); 20 | Serial.begin(57600); 21 | rd.setPacketFormat(2, 1, 0); // размер чисел - 2, размер пакета - 1 22 | } 23 | 24 | void loop(void){ 25 | unsigned int v; 26 | if( rd.receivePacket() ){ 27 | v = rd.getPacketValue(0); 28 | digitalWrite(ledPin, v); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/sflow-transmitter/sflow-transmitter.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2016 O. Evsegneev 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | version 2 as published by the Free Software Foundation. 7 | */ 8 | 9 | /** 10 | * Example for sensor data transmitting. 11 | */ 12 | #include 13 | 14 | SerialFlow rd(&Serial); 15 | 16 | const byte temp_pin = A0; 17 | const unsigned long data_to = 100; 18 | unsigned long tm, data_next; 19 | 20 | void setup(void){ 21 | pinMode( temp_pin, INPUT); 22 | 23 | rd.setPacketFormat(2, 1, 0); // размер чисел - 2, размер пакета - 1 24 | } 25 | 26 | void loop(void){ 27 | unsigned int v; 28 | tm = millis(); 29 | if( tm > data_next ){ 30 | data_next = tm + data_to; 31 | v = analogRead( temp_pin ); 32 | rd.setPacketValue( v ); 33 | rd.sendPacket(); 34 | } 35 | } 36 | 37 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/sflow_simple_adc/sflow_simple_adc.ino: -------------------------------------------------------------------------------- 1 | const int adc1Pin = A0; 2 | int val = 0; 3 | 4 | void setup(){ 5 | Serial.begin(115200); 6 | pinMode(adc1Pin, INPUT); 7 | } 8 | 9 | void loop(){ 10 | val = analogRead(adc1Pin); 11 | val = ( val/1023.0 )*5.0*1000/10; 12 | Serial.write(val); 13 | delay(20); 14 | } 15 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/sfmon_sflow_adxl/sfmon_sflow_adxl.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ADXL345 accelerometer; 5 | SerialFlow rd(&Serial); // RX, TX 6 | 7 | Vector araw; 8 | 9 | void setup() { 10 | //Serial.begin(115200); 11 | rd.setPacketFormat(2, 3, 0); 12 | rd.begin(115200); 13 | 14 | accelerometer.begin(); 15 | accelerometer.setRange(ADXL345_RANGE_16G); 16 | } 17 | 18 | void loop() { 19 | araw = accelerometer.readRaw(); 20 | rd.setPacketValue( araw.XAxis + 58 ); 21 | rd.setPacketValue( araw.YAxis - 30 ); 22 | rd.setPacketValue( araw.ZAxis - 1420 ); 23 | rd.sendPacket(); 24 | //Serial.println( araw.YAxis ); 25 | delay(20); 26 | } 27 | 28 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/sfmon_sflow_adxlf/sfmon_sflow_adxlf.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | ADXL345 accelerometer; 5 | SerialFlow rd(&Serial); // RX, TX 6 | 7 | Vector araw; 8 | 9 | float fx,fy,fz; 10 | const float k = 0.2; 11 | 12 | void setup() { 13 | rd.setPacketFormat(2, 3, 0); 14 | rd.begin(115200); 15 | 16 | accelerometer.begin(); 17 | accelerometer.setRange(ADXL345_RANGE_16G); 18 | 19 | fx = 0; 20 | fy = 0; 21 | fz = 0; 22 | } 23 | 24 | void loop() { 25 | araw = accelerometer.readRaw(); 26 | 27 | fx = fx*(1-k) + (araw.XAxis + 58)*k; 28 | fy = fy*(1-k) + (araw.YAxis - 30)*k; 29 | fz = fz*(1-k) + (araw.ZAxis - 1420)*k; 30 | 31 | rd.setPacketValue( int(fx) ); 32 | rd.setPacketValue( int(fy) ); 33 | rd.setPacketValue( int(fz) ); 34 | rd.sendPacket(); 35 | delay(10); 36 | } 37 | 38 | -------------------------------------------------------------------------------- /sketches/Link.SFlow/sfmon_sflow_hum_temp/sfmon_sflow_hum_temp.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | const int adc1Pin = A0; 4 | const int adc2Pin = A1; 5 | 6 | SerialFlow rd(&Serial); 7 | 8 | void setup(){ 9 | rd.setPacketFormat(2, 2, 0); 10 | rd.begin(115200); 11 | } 12 | 13 | void loop(){ 14 | int val1, val2; 15 | val1 = analogRead(adc1Pin); 16 | val2 = analogRead(adc2Pin); 17 | rd.setPacketValue( val1/4 ); 18 | rd.setPacketValue( ( val2/1023.0 )*500 ); 19 | rd.sendPacket(); 20 | delay(100); 21 | } 22 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/serial_first/serial_first.ino: -------------------------------------------------------------------------------- 1 | byte ledPin = 13; 2 | byte ledState = 0; 3 | byte v; 4 | 5 | unsigned long tm, send_next; 6 | unsigned int send_to = 500; // отправка каждые 500мс 7 | 8 | void setup() { 9 | Serial.begin(9600); 10 | pinMode( ledPin, OUTPUT ); 11 | } 12 | 13 | void loop() { 14 | // проверка наличия данных в буфере UART 15 | if( Serial.available() ){ 16 | v = Serial.read(); 17 | digitalWrite( ledPin, ledState ); 18 | ledState = !ledState; 19 | } 20 | // отправка данных по таймауту 21 | tm = millis(); 22 | if( tm > send_next ){ 23 | send_next = tm + send_to; 24 | Serial.write('A'); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/serial_master/serial_master.ino: -------------------------------------------------------------------------------- 1 | void setup() { 2 | Serial.begin(9600); 3 | } 4 | 5 | void loop() { 6 | Serial.write('A'); 7 | delay(500); 8 | } 9 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/serial_master_photo/serial_master_photo.ino: -------------------------------------------------------------------------------- 1 | byte photoPin = A0; 2 | 3 | void setup() { 4 | Serial.begin(9600); 5 | pinMode(photoPin, INPUT); 6 | } 7 | 8 | void loop() { 9 | long val = analogRead(photoPin); 10 | val = val*255/1023.0; 11 | Serial.write(val); 12 | delay(100); 13 | } 14 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/serial_slave/serial_slave.ino: -------------------------------------------------------------------------------- 1 | byte ledPin = 13; 2 | byte ledState = 0; 3 | byte v; 4 | 5 | void setup() { 6 | Serial.begin(9600); 7 | pinMode( ledPin, OUTPUT ); 8 | } 9 | 10 | void loop() { 11 | if( Serial.available() ){ 12 | v = Serial.read(); 13 | digitalWrite( ledPin, ledState ); 14 | ledState = !ledState; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/serial_slave_photo/serial_slave_photo.ino: -------------------------------------------------------------------------------- 1 | byte ledPin = 3; 2 | 3 | void setup() { 4 | Serial.begin(9600); 5 | pinMode( ledPin, OUTPUT ); 6 | } 7 | 8 | void loop() { 9 | if( Serial.available() ){ 10 | byte v = Serial.read(); 11 | analogWrite( ledPin, v); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/serial_test_master/serial_test_master.ino: -------------------------------------------------------------------------------- 1 | void setup() { 2 | Serial.begin(9600); 3 | Serial3.begin(9600); 4 | } 5 | 6 | void loop() { 7 | Serial3.write('A'); 8 | if(Serial3.available()){ 9 | Serial.write( Serial3.read() ); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/serial_test_slave/serial_test_slave.ino: -------------------------------------------------------------------------------- 1 | void setup() { 2 | Serial.begin(9600); 3 | } 4 | 5 | void loop() { 6 | if(Serial.available()){ 7 | Serial.write( Serial.read() ); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/uart_master/uart_master.ino: -------------------------------------------------------------------------------- 1 | #define CMD_LED 0xA1 2 | 3 | #include 4 | 5 | SerialFlow rd(&Serial); 6 | 7 | const int btn = A2; 8 | 9 | void setup(){ 10 | rd.setPacketFormat(1, 2, 0); // размер одного значения в байтах, размер пакета в значениях, 11 | rd.begin(9600); 12 | 13 | pinMode(btn, INPUT); 14 | } 15 | 16 | void loop(){ 17 | if( digitalRead(btn) ){ 18 | rd.setPacketValue(CMD_LED); 19 | rd.setPacketValue(1); 20 | rd.sendPacket(); 21 | } else { 22 | rd.setPacketValue(CMD_LED); 23 | rd.setPacketValue(0); 24 | rd.sendPacket(); 25 | } 26 | delay(100); 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /sketches/Link.UART_lesson/uart_master_fflop/uart_master_fflop.ino: -------------------------------------------------------------------------------- 1 | #define CMD_LED 0xA1 2 | 3 | #include 4 | 5 | SerialFlow rd(&Serial); 6 | 7 | const int btn = A2; 8 | byte flag = 0; 9 | 10 | void setup(){ 11 | rd.setPacketFormat(1, 2); // размер одного значения в байтах, размер пакета в значениях, 12 | rd.begin(9600); 13 | 14 | pinMode(btn, INPUT); 15 | } 16 | 17 | void loop(){ 18 | rd.setPacketValue(CMD_LED); 19 | rd.setPacketValue(flag); 20 | rd.sendPacket(); 21 | flag =! flag; 22 | delay(100); 23 | } 24 | 25 | 26 | -------------------------------------------------------------------------------- /sketches/Motor.L298N_lesson/l298n-simple/l298n-simple.ino: -------------------------------------------------------------------------------- 1 | byte ena = 3; 2 | byte in1 = 4; 3 | byte in2 = 5; 4 | 5 | void setup() { 6 | pinMode( ena, OUTPUT ); 7 | pinMode( in1, OUTPUT ); 8 | pinMode( in2, OUTPUT ); 9 | } 10 | 11 | void loop() { 12 | // выставляем 100% мощность на моторе А - 255 из 255 13 | analogWrite( ena, 255 ); 14 | // выставляем режим мотора - вращение по часовой 15 | digitalWrite( in1, HIGH ); 16 | digitalWrite( in2, LOW ); 17 | delay(3000); // пауза 3сек 18 | 19 | // выставляем мощность на мотора А - 150 из 255 20 | analogWrite( ena, 150 ); 21 | // режим мотора - вращение против часово 22 | digitalWrite( in1, LOW ); 23 | digitalWrite( in2, HIGH ); 24 | delay(3000); // пауза 3сек 25 | } 26 | -------------------------------------------------------------------------------- /sketches/Motor.ROC.TB6612_lesson/test/test.ino: -------------------------------------------------------------------------------- 1 | const byte enPin = 3; 2 | const byte dirPin[2] = {2,4}; 3 | 4 | void setup() { 5 | pinMode(enPin, OUTPUT); 6 | pinMode(dirPin[0], OUTPUT); 7 | pinMode(dirPin[1], OUTPUT); 8 | 9 | digitalWrite(dirPin[0], HIGH); 10 | digitalWrite(dirPin[1], LOW); 11 | analogWrite(enPin,255); 12 | delay(2000); 13 | analogWrite(enPin,0); 14 | } 15 | 16 | void loop() { 17 | digitalWrite(dirPin[0], HIGH); 18 | digitalWrite(dirPin[1], LOW); 19 | for(byte i=0; i<256; i++){ 20 | analogWrite(enPin,i); 21 | delay(10); 22 | } 23 | for(byte i=0; i<256; i++){ 24 | analogWrite(enPin,255-i); 25 | delay(10); 26 | } 27 | delay(1000); 28 | digitalWrite(dirPin[0], LOW); 29 | digitalWrite(dirPin[1], HIGH); 30 | for(byte i=0; i<256; i++){ 31 | analogWrite(enPin,i); 32 | delay(10); 33 | } 34 | for(byte i=0; i<256; i++){ 35 | analogWrite(enPin,255-i); 36 | delay(10); 37 | } 38 | delay(1000); 39 | } 40 | -------------------------------------------------------------------------------- /sketches/Motor.ROC.servo_lesson/servo_test/config.h: -------------------------------------------------------------------------------- 1 | #define SERVOMIN 150 2 | #define SERVOMAX 600 3 | 4 | #define HIP_SPD 2 5 | #define LEG_SPD 5 6 | #define EYE_SPD 1 7 | 8 | #define SCAN_STEPS 5 9 | #define WALK_BWD_STEPS 8 10 | 11 | // states 12 | #define ST_IDLE 1 13 | #define ST_STAND 2 14 | #define ST_SWEEP 4 15 | #define ST_WALK_FWD 8 16 | #define ST_WALK_BWD 16 17 | #define ST_TURN_L 32 18 | #define ST_TURN_R 64 19 | #define ST_STRAFE_L 128 20 | #define ST_STRAFE_R 256 21 | #define ST_WAIT 512 22 | #define ST_SCAN 1024 23 | 24 | #define ST_BUSY 2048 25 | 26 | // state times 27 | #define ST_IDLE 0 28 | #define ST_STAND_T 2000 29 | #define ST_SWEEP_T 4000 30 | #define ST_WALK_T 5000 31 | 32 | // numbers 33 | #define FRH 0 //front right hip 34 | #define FRL 1 //front right leg 35 | #define FLH 2 //front left hip 36 | #define FLL 3 //front left leg 37 | #define RLH 4 //rear left hip 38 | #define RLL 5 //rear left leg 39 | #define RRH 6 //rear right hip 40 | #define RRL 7 //rear right leg 41 | #define BBN 8 //sevor for backbone 42 | #define EYE 9 //sevor for sensor 43 | #define LSR 10 //laser 44 | 45 | // speed 46 | #define SPD_STAND 3 47 | #define SPD_SWEEP 1 48 | #define SPD_WALK 1 49 | 50 | // timeout 51 | #define STEP_TO_STAND 200 52 | #define STEP_TO_SWEEP 1000 53 | #define STEP_TO_WALK 200 54 | 55 | // pins 56 | #define FRH_PIN 0 57 | #define FRL_PIN 1 58 | #define FLH_PIN 2 59 | #define FLL_PIN 3 60 | #define RLH_PIN 4 61 | #define RLL_PIN 5 62 | #define RRH_PIN 6 63 | #define RRL_PIN 7 64 | #define BBN_PIN 8 65 | #define EYE_PIN 9 66 | #define LSR_PIN 14 67 | 68 | // defaults 69 | #define FRH_DEF 45 70 | #define FRL_DEF 74 + 60 71 | #define FLH_DEF 75 72 | #define FLL_DEF 86 - 60 73 | #define RLH_DEF 45 74 | #define RLL_DEF 74 + 60 75 | #define RRH_DEF 80 76 | #define RRL_DEF 91 - 60 77 | #define BBN_DEF 83 78 | #define EYE_DEF 75 79 | #define LSR_DEF 90 80 | 81 | -------------------------------------------------------------------------------- /sketches/Motor.ROC.servo_lesson/servo_test/servo_test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SERVOMIN 150 4 | #define SERVOMAX 600 5 | 6 | Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); 7 | 8 | void setup(){ 9 | pwm.begin(); 10 | pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates 11 | } 12 | 13 | void loop(){ 14 | uint16_t p; 15 | p = map(45, 0, 180, SERVOMIN, SERVOMAX); 16 | pwm.setPWM(0, 0, p); 17 | delay(500); 18 | p = map(135, 0, 180, SERVOMIN, SERVOMAX); 19 | pwm.setPWM(0, 0, p); 20 | delay(500); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /sketches/Motor.Servo_lesson/ardu-servo-photo/ardu-servo-photo.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | Servo myservo; 4 | 5 | const byte photoPin = A0; 6 | const byte servoPin = 2; 7 | 8 | void setup() { 9 | myservo.attach(servoPin); 10 | } 11 | 12 | void loop() { 13 | int val = analogRead(photoPin); // reads the value of the potentiometer (value between 0 and 1023) 14 | val = map((1023-val)*2.5, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) 15 | myservo.write(val); // sets the servo position according to the scaled value 16 | delay(15); // waits for the servo to get there 17 | } 18 | 19 | -------------------------------------------------------------------------------- /sketches/Motor.Stepper/step-cnc-shield/step-cnc-shield.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define RPM_1 3200//6400 5 | #define ACC_1 3200//6400 6 | #define MOT_STEPS_1 3200//6400 7 | 8 | #define M0 0 9 | 10 | AccelStepper *mtr[1]; 11 | 12 | const double rel[1] = {66.6666}; 13 | 14 | const byte mtrPins[3][2] = {{3,6}}; // step, dir 15 | const byte mtrEnPin = 8; 16 | 17 | byte trigger = 0; 18 | 19 | void setup() { 20 | Serial.begin(9600); 21 | 22 | mtr[M0] = new AccelStepper(AccelStepper::DRIVER, mtrPins[M0][0], mtrPins[M0][1]); 23 | 24 | pinMode(mtrEnPin, OUTPUT); 25 | 26 | mtr[M0]->setMaxSpeed(RPM_1); 27 | mtr[M0]->setAcceleration(ACC_1); 28 | 29 | digitalWrite(mtrEnPin, LOW); 30 | 31 | mtr[M0]->moveTo(500); 32 | 33 | delay(1000); 34 | } 35 | 36 | void loop() { 37 | if (mtr[M0]->distanceToGo() == 0) 38 | mtr[M0]->moveTo(-mtr[M0]->currentPosition()); 39 | 40 | mtr[M0]->run(); 41 | } 42 | -------------------------------------------------------------------------------- /sketches/Motor.Stepper/step/step.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #define RPM_1 3200//6400 5 | #define ACC_1 3200//6400 6 | #define MOT_STEPS_1 3200//6400 7 | 8 | #define M0 0 9 | 10 | AccelStepper *mtr[1]; 11 | 12 | const double rel[1] = {66.6666}; 13 | 14 | //const byte mtrPins[3][2] = {{9,3}}; // step, dir 15 | //const byte mtrEnPin = 5; 16 | const byte mtrPins[3][2] = {{2,5}}; // step, dir 17 | const byte mtrEnPin = 8; 18 | 19 | byte trigger = 0; 20 | 21 | void setup() { 22 | Serial.begin(9600); 23 | 24 | mtr[M0] = new AccelStepper(AccelStepper::DRIVER, mtrPins[M0][0], mtrPins[M0][1]); 25 | 26 | pinMode(mtrEnPin, OUTPUT); 27 | pinMode(A0, INPUT); 28 | pinMode(13, OUTPUT); 29 | 30 | mtr[M0]->setMaxSpeed(RPM_1); 31 | mtr[M0]->setAcceleration(ACC_1); 32 | 33 | digitalWrite(mtrEnPin, LOW); 34 | 35 | delay(1000); 36 | } 37 | 38 | void loop() { 39 | int v = 1;//digitalRead(A0); 40 | if( v ){ 41 | digitalWrite(13, HIGH); 42 | } else { 43 | digitalWrite(13, LOW); 44 | } 45 | if( !trigger && v ){ 46 | mtr[0]->move(1000); 47 | trigger = 1; 48 | } 49 | if( trigger && !v ){ 50 | mtr[0]->move(-1000); 51 | trigger = 0; 52 | } 53 | mtr[0]->run(); 54 | } 55 | -------------------------------------------------------------------------------- /sketches/Motor.Stepper/stepper_control_A4988/stepper_control_A4988.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "BasicStepperDriver.h" 3 | 4 | #define MOTOR_STEPS 48 5 | 6 | #define DIR 2 7 | #define STEP 3 8 | 9 | BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP); 10 | 11 | void setup() { 12 | stepper.setRPM(120); 13 | stepper.move(96); 14 | delay(2000); 15 | stepper.move(-96); 16 | } 17 | 18 | void loop() { 19 | } 20 | -------------------------------------------------------------------------------- /sketches/Motor.Stepper/stepper_uln/stepper_uln.ino: -------------------------------------------------------------------------------- 1 | int in1 = 2; 2 | int in2 = 3; 3 | int in3 = 4; 4 | int in4 = 5; 5 | const int dl =50; 6 | void setup() { 7 | pinMode(in1, OUTPUT); 8 | pinMode(in2, OUTPUT); 9 | pinMode(in3, OUTPUT); 10 | pinMode(in4, OUTPUT); 11 | } 12 | void loop() { 13 | digitalWrite( in1, LOW ); 14 | digitalWrite( in2, LOW ); 15 | digitalWrite( in3, LOW ); 16 | digitalWrite( in4, HIGH ); 17 | delay(dl); 18 | digitalWrite( in1, LOW ); 19 | digitalWrite( in2, LOW ); 20 | digitalWrite( in3, HIGH ); 21 | digitalWrite( in4, HIGH ); 22 | delay(dl); 23 | digitalWrite( in1, LOW ); 24 | digitalWrite( in2, LOW ); 25 | digitalWrite( in3, HIGH ); 26 | digitalWrite( in4, LOW ); 27 | delay(dl); 28 | digitalWrite( in1, LOW ); 29 | digitalWrite( in2, HIGH ); 30 | digitalWrite( in3, HIGH ); 31 | digitalWrite( in4, LOW ); 32 | delay(dl); 33 | digitalWrite( in1, LOW ); 34 | digitalWrite( in2, HIGH ); 35 | digitalWrite( in3, LOW ); 36 | digitalWrite( in4, LOW ); 37 | delay(dl); 38 | digitalWrite( in1, HIGH ); 39 | digitalWrite( in2, HIGH ); 40 | digitalWrite( in3, LOW ); 41 | digitalWrite( in4, LOW ); 42 | delay(dl); 43 | digitalWrite( in1, HIGH ); 44 | digitalWrite( in2, LOW ); 45 | digitalWrite( in3, LOW ); 46 | digitalWrite( in4, LOW ); 47 | delay(dl); 48 | digitalWrite( in1, HIGH ); 49 | digitalWrite( in2, LOW ); 50 | digitalWrite( in3, LOW ); 51 | digitalWrite( in4, HIGH ); 52 | delay(dl); 53 | } 54 | -------------------------------------------------------------------------------- /sketches/OSD/Spi.cpp: -------------------------------------------------------------------------------- 1 | // Get the common arduino functions 2 | #if defined(ARDUINO) && ARDUINO >= 100 3 | #include "Arduino.h" 4 | #else 5 | #include "wiring.h" 6 | #endif 7 | #include "Spi.h" 8 | 9 | //---------- constructor ---------------------------------------------------- 10 | 11 | SPI::SPI() 12 | { 13 | // initialize the SPI pins 14 | pinMode(SCK_PIN, OUTPUT); 15 | pinMode(MOSI_PIN, OUTPUT); 16 | pinMode(MISO_PIN, INPUT); 17 | pinMode(SS_PIN, OUTPUT); // <------- !!! (Remember! This pin will select USB host chip Max3421) 18 | 19 | // enable SPI Master, MSB, SPI mode 0, FOSC/4 20 | mode(0); 21 | } 22 | 23 | //------------------ mode --------------------------------------------------- 24 | 25 | void SPI::mode(byte config) 26 | { 27 | byte tmp; 28 | 29 | // enable SPI master with configuration byte specified 30 | SPCR = 0; 31 | SPCR = (config & 0x7F) | (1< 0) delayMicroseconds(period); 49 | while (!(SPSR & (1<= 100 6 | #include "Arduino.h" 7 | #else 8 | #include "wiring.h" 9 | #endif 10 | 11 | #define SCK_PIN 13 12 | #define MISO_PIN 12 13 | #define MOSI_PIN 11 14 | #define SS_PIN 10 // <------- !!! (Remember! This pin will select USB host chip Max3421) 15 | 16 | class SPI 17 | { 18 | public: 19 | SPI(void); 20 | void mode(byte); 21 | byte transfer(byte); 22 | byte transfer(byte, byte); 23 | }; 24 | 25 | extern SPI Spi; 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /sketches/PWM_lesson/pwm-monit/pwm-monit.ino: -------------------------------------------------------------------------------- 1 | const byte potPin = A0; 2 | const byte in1Pin = 4; 3 | const byte in2Pin = 5; 4 | const byte enPin = 3; 5 | 6 | void setup() { 7 | pinMode(potPin, INPUT); 8 | pinMode(in1Pin, OUTPUT); 9 | pinMode(in2Pin, OUTPUT); 10 | pinMode(enPin, OUTPUT); 11 | 12 | digitalWrite(in1Pin, HIGH); 13 | digitalWrite(in2Pin, LOW); 14 | } 15 | 16 | void loop() { 17 | int v = analogRead(potPin); 18 | float b = 255*(v/1023.0); 19 | analogWrite(enPin, int(b)); 20 | } 21 | -------------------------------------------------------------------------------- /sketches/Piano_article/piano/piano.ino: -------------------------------------------------------------------------------- 1 | #define TONE_TIME 50 2 | #define TONE_DELAY 0 3 | 4 | const byte spkPin = 53; 5 | 6 | void setup() { 7 | pinMode( spkPin, OUTPUT ); 8 | //Serial.begin(9600); 9 | } 10 | 11 | void loop() { 12 | //Serial.println(analogRead(A0)); 13 | if( analogRead(A0)<1000 ){ 14 | tone(spkPin,261,TONE_TIME); 15 | delay(TONE_DELAY); 16 | } 17 | if( analogRead(A1)<1000 ){ 18 | tone(spkPin,294,TONE_TIME); 19 | delay(TONE_DELAY); 20 | } 21 | if( analogRead(A2)<1000 ){ 22 | tone(spkPin,329,TONE_TIME); 23 | delay(TONE_DELAY); 24 | } 25 | if( analogRead(A3)<1000 ){ 26 | tone(spkPin,349,TONE_TIME); 27 | delay(TONE_DELAY); 28 | } 29 | if( analogRead(A4)<1000 ){ 30 | tone(spkPin,392,TONE_TIME); 31 | delay(TONE_DELAY); 32 | } 33 | if( analogRead(A5)<1000 ){ 34 | tone(spkPin,440,TONE_TIME); 35 | delay(TONE_DELAY); 36 | } 37 | if( analogRead(A6)<1000 ){ 38 | tone(spkPin,493,TONE_TIME); 39 | delay(TONE_DELAY); 40 | } 41 | if( analogRead(A7)<1000 ){ 42 | tone(spkPin,523,TONE_TIME); 43 | delay(TONE_DELAY); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sketches/ROC.GPIO_Expander_lesson/ROC.Expander/ROC.Expander.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Adafruit_MCP23017.h" 3 | 4 | Adafruit_MCP23017 mcp; 5 | 6 | void setup() { 7 | mcp.begin(7); 8 | 9 | for(byte i=0; i<16; i++){ 10 | mcp.pinMode(i, OUTPUT); 11 | } 12 | } 13 | 14 | void loop() { 15 | for(int i=0; i<8; i++){ 16 | mcp.digitalWrite(i, HIGH); 17 | mcp.digitalWrite(15-i, HIGH); 18 | delay(30); 19 | if(i>0){ 20 | mcp.digitalWrite(i-1, LOW); 21 | mcp.digitalWrite(15-i+1, LOW); 22 | delay(30); 23 | } 24 | } 25 | for(int i=7; i>=0; i--){ 26 | mcp.digitalWrite(i, HIGH); 27 | mcp.digitalWrite(15-i, HIGH); 28 | delay(30); 29 | if(i<7){ 30 | mcp.digitalWrite(i+1, LOW); 31 | mcp.digitalWrite(15-i-1, LOW); 32 | delay(30); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sketches/ROC.GPIO_Expander_lesson/expander-btn/expander-btn.ino: -------------------------------------------------------------------------------- 1 | #include "Adafruit_MCP23017.h" 2 | 3 | const byte ledPin = 0; 4 | const byte btnPin = 1; 5 | 6 | Adafruit_MCP23017 mcp; 7 | 8 | void setup() { 9 | mcp.begin(7); // инициализация модуля с адресом 0x07 10 | mcp.pinMode(ledPin, OUTPUT); // настройка контакта G0 на вывод 11 | mcp.pinMode(btnPin, INPUT); // настройка контакта G1 на ввод 12 | mcp.pullUp(btnPin, HIGH); // подтяжка контакта G1 к питанию 13 | } 14 | 15 | void loop() { 16 | if(mcp.digitalRead(btnPin)==LOW) // если кнопка нажата, то 17 | mcp.digitalWrite(ledPin, HIGH); // зажигаем светодиод 18 | else // иначе 19 | mcp.digitalWrite(ledPin, LOW); // гасим светодиод 20 | } 21 | -------------------------------------------------------------------------------- /sketches/ROC.GPIO_Expander_lesson/expander-int/expander-int.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | Adafruit_MCP23017 mcp; 4 | 5 | // к этому контакту Arduino подключен встроенный светодиод 6 | const byte ledPin = 13; 7 | 8 | // к этому контакту расширителя подключен внешний светодиод 9 | const byte mcpPin = 0; 10 | 11 | // к этому контакту Arduino подключен контакт IA расширителя 12 | const byte arduinoIntPin = 3; 13 | 14 | // на 3-м контакте Arduino обслуживается прерывание №1 15 | const byte arduinoInterrupt = 1; 16 | 17 | // переменная - флаг, которая примет значение true 18 | // при возникновении прерывания 19 | volatile boolean awakenByInterrupt = false; 20 | 21 | void setup(){ 22 | // настраиваем режим контакта для прерывания Arduino 23 | pinMode(arduinoIntPin,INPUT); 24 | 25 | // инициализируем расширитель с адресом 7 26 | mcp.begin(7); 27 | 28 | // настраиваем прерывания расширителя 29 | // режим зеркалирования отключен - false 30 | // режим открытого стока отключен - false 31 | // инверсия сигнала включена - LOW 32 | mcp.setupInterrupts(false, false, LOW); 33 | 34 | mcp.pinMode(mcpPin, INPUT); // установка режима 35 | mcp.pullUp(mcpPin, HIGH); // подтяжка контакта к питанию 36 | 37 | // активируем прерывание расширителя на контакте mcpPin 38 | // в режиме детектирования спада импульса - FALLING 39 | mcp.setupInterruptPin(mcpPin, FALLING); 40 | 41 | // настраиваем режим контакта для светодиода 42 | pinMode(ledPin, OUTPUT); 43 | 44 | // активируем прерывание Arduino под номером arduinoInterrupt 45 | // с вызовом функции intCallBack 46 | // в режиме детектирования спада импульса - FALLING 47 | attachInterrupt(arduinoInterrupt,intCallBack,FALLING); 48 | } 49 | 50 | // обработчик прерывания Arduino 51 | void intCallBack(){ 52 | awakenByInterrupt = true; 53 | } 54 | 55 | void handleInterrupt(){ 56 | // отключаем прерывание на время пока выполняется обработчик 57 | detachInterrupt(arduinoInterrupt); 58 | 59 | // мигаем один раз светодиодом 60 | digitalWrite(ledPin,HIGH); 61 | delay(100); 62 | digitalWrite(ledPin,LOW); 63 | delay(100); 64 | 65 | // ждём, пока кнопку не отпустят 66 | while( !mcp.digitalRead(mcpPin)); 67 | 68 | // сбрасываем флаг нажатия 69 | awakenByInterrupt = false; 70 | 71 | // включаем прерывание обратно 72 | attachInterrupt(arduinoInterrupt,intCallBack,FALLING); 73 | } 74 | 75 | void loop(){ 76 | // если прерывание сработало и флаг истина 77 | if(awakenByInterrupt){ 78 | // делаем, что задумали 79 | handleInterrupt(); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /sketches/ROC.GPIO_Expander_lesson/expander-led/expander-led.ino: -------------------------------------------------------------------------------- 1 | #include "Adafruit_MCP23017.h" 2 | 3 | const byte ledPin = 0; 4 | 5 | Adafruit_MCP23017 mcp; 6 | 7 | void setup() { 8 | mcp.begin(7); // инициализация модуля с адресом 0x07 9 | mcp.pinMode(ledPin, OUTPUT); // настройка контакта G0 на вывод 10 | } 11 | 12 | void loop() { 13 | mcp.digitalWrite(ledPin, HIGH); 14 | delay(200); 15 | mcp.digitalWrite(ledPin, LOW); 16 | delay(200); 17 | } 18 | -------------------------------------------------------------------------------- /sketches/SDCard_lesson/CardInfo/CardInfo.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | Sd2Card card; 5 | SdVolume volume; 6 | SdFile root; 7 | 8 | const int chipSelect = 4; 9 | 10 | void setup() { 11 | Serial.begin(9600); 12 | while (!Serial) { 13 | ; // wait for serial port to connect. Needed for native USB port only 14 | } 15 | 16 | Serial.print("\nInitializing SD card..."); 17 | 18 | if (!card.init(SPI_HALF_SPEED, chipSelect)) { 19 | Serial.println("initialization failed. Things to check:"); 20 | Serial.println("* is a card inserted?"); 21 | Serial.println("* is your wiring correct?"); 22 | Serial.println("* did you change the chipSelect pin to match your shield or module?"); 23 | return; 24 | } else { 25 | Serial.println("Wiring is correct and a card is present."); 26 | } 27 | 28 | Serial.print("\nCard type: "); 29 | switch (card.type()) { 30 | case SD_CARD_TYPE_SD1: 31 | Serial.println("SD1"); 32 | break; 33 | case SD_CARD_TYPE_SD2: 34 | Serial.println("SD2"); 35 | break; 36 | case SD_CARD_TYPE_SDHC: 37 | Serial.println("SDHC"); 38 | break; 39 | default: 40 | Serial.println("Unknown"); 41 | } 42 | 43 | // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32 44 | if (!volume.init(card)) { 45 | Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card"); 46 | return; 47 | } 48 | 49 | 50 | // print the type and size of the first FAT-type volume 51 | uint32_t volumesize; 52 | Serial.print("\nVolume type is FAT"); 53 | Serial.println(volume.fatType(), DEC); 54 | Serial.println(); 55 | 56 | volumesize = volume.blocksPerCluster(); // clusters are collections of blocks 57 | volumesize *= volume.clusterCount(); // we'll have a lot of clusters 58 | volumesize *= 512; // SD card blocks are always 512 bytes 59 | Serial.print("Volume size (bytes): "); 60 | Serial.println(volumesize); 61 | Serial.print("Volume size (Kbytes): "); 62 | volumesize /= 1024; 63 | Serial.println(volumesize); 64 | Serial.print("Volume size (Mbytes): "); 65 | volumesize /= 1024; 66 | Serial.println(volumesize); 67 | 68 | 69 | Serial.println("\nFiles found on the card (name, date and size in bytes): "); 70 | root.openRoot(volume); 71 | 72 | // list all files in the card with date and size 73 | root.ls(LS_R | LS_DATE | LS_SIZE); 74 | } 75 | 76 | 77 | void loop(void) { 78 | 79 | } 80 | -------------------------------------------------------------------------------- /sketches/SDCard_lesson/Datalogger/Datalogger.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int chipSelect = 4; 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | while (!Serial) { 9 | ; // wait for serial port to connect. Needed for native USB port only 10 | } 11 | 12 | if (!SD.begin(chipSelect)) { 13 | Serial.println("Card failed, or not present"); 14 | return; 15 | } 16 | String dataString = "Hello from RobotClass"; 17 | 18 | File dataFile = SD.open("test.txt", FILE_WRITE); 19 | 20 | if (dataFile) { 21 | dataFile.println(dataString); 22 | dataFile.close(); 23 | Serial.println("Success!"); 24 | } 25 | else { 26 | Serial.println("error opening file"); 27 | } 28 | } 29 | 30 | void loop() { 31 | } 32 | -------------------------------------------------------------------------------- /sketches/SDCard_lesson/Datalogger_ds18b20/Datalogger_ds18b20.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | OneWire ds(2); 6 | File dataFile; 7 | 8 | const int chipSelect = 4; 9 | 10 | void setup() { 11 | pinMode(, OUTPUT); 12 | Serial.begin(9600); 13 | while (!Serial) { 14 | ; // wait for serial port to connect. Needed for native USB port only 15 | } 16 | 17 | if (!SD.begin(chipSelect)) { 18 | Serial.println("Card failed, or not present"); 19 | return; 20 | } 21 | Serial.println("Ready"); 22 | } 23 | 24 | void loop() { 25 | byte i; 26 | byte present = 0; 27 | byte data[12]; 28 | byte addr[8]; 29 | float celsius; 30 | 31 | if ( !ds.search(addr)) { 32 | Serial.println("No more addresses."); 33 | //Serial.println(); 34 | ds.reset_search(); 35 | delay(250); 36 | return; 37 | } 38 | 39 | ds.reset(); 40 | ds.select(addr); 41 | ds.write(0x44, 1); 42 | 43 | delay(1000); 44 | 45 | present = ds.reset(); 46 | ds.select(addr); 47 | ds.write(0xBE); // Read Scratchpad 48 | 49 | for ( i = 0; i < 9; i++) { 50 | data[i] = ds.read(); 51 | } 52 | 53 | int16_t raw = (data[1] << 8) | data[0]; 54 | byte cfg = (data[4] & 0x60); 55 | if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms 56 | else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms 57 | else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms 58 | 59 | celsius = (float)raw / 16.0; 60 | Serial.print("t="); 61 | Serial.println(celsius); 62 | 63 | dataFile = SD.open("temp.txt", FILE_WRITE); 64 | if (dataFile) { 65 | dataFile.println(celsius); 66 | dataFile.close(); 67 | } 68 | else { 69 | Serial.println("error opening file"); 70 | } 71 | //delay(500); 72 | } 73 | -------------------------------------------------------------------------------- /sketches/SDCard_lesson/ReadWrite/ReadWrite.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | const int chipSelect = 4; 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | 9 | if( !SD.begin( chipSelect )){ 10 | Serial.println("initialization failed!"); 11 | return; 12 | } 13 | 14 | File myFile = SD.open("test.txt"); 15 | if (myFile) { 16 | while (myFile.available()) { 17 | Serial.write(myFile.read()); 18 | } 19 | myFile.close(); 20 | } else { 21 | Serial.println("error opening test.txt"); 22 | } 23 | } 24 | 25 | void loop() { 26 | // nothing happens after setup 27 | } 28 | 29 | 30 | -------------------------------------------------------------------------------- /sketches/Segway_mpu/Madgwick.h: -------------------------------------------------------------------------------- 1 | extern volatile float beta; 2 | extern volatile float q0, q1, q2, q3; 3 | 4 | void MadgwickAHRSupdate(float tdelta, float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz); 5 | void MadgwickAHRSupdateIMU(float tdelta, float gx, float gy, float gz, float ax, float ay, float az); 6 | float invSqrt(float x); 7 | void quat2Euler( float q[4], float e[3] ); 8 | -------------------------------------------------------------------------------- /sketches/Segway_mpu/segway_mpu.ino: -------------------------------------------------------------------------------- 1 | #define betaDef 0.2f 2 | #include "I2Cdev.h" 3 | #include "MPU6050.h" 4 | #include "Madgwick.h" 5 | #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE 6 | #include "Wire.h" 7 | #endif 8 | unsigned long tm, imu_t, prn_t; 9 | unsigned int imu_to = 20; 10 | 11 | const unsigned int prn_to = 100; 12 | 13 | float tdelta; 14 | int16_t ax, ay, az; 15 | int16_t gx_raw, gy_raw, gz_raw; 16 | MPU6050 accelgyro; 17 | //#define OUTPUT_READABLE_ACCELGYRO 18 | #define TO_RAD 0.01745329252f 19 | 20 | bool blinkState = false; 21 | 22 | float imu[3]; 23 | float quat[4]; 24 | float e[3]; 25 | 26 | void setup() { 27 | #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE 28 | Wire.begin(); 29 | #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE 30 | Fastwire::setup(400, true); 31 | #endif 32 | Serial.begin(9600); 33 | Serial.println("Initializing I2C devices..."); 34 | accelgyro.initialize(); 35 | Serial.println("Testing device connections..."); 36 | Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); 37 | } 38 | 39 | void loop() { 40 | accelgyro.getMotion6(&ax, &ay, &az, &gx_raw, &gy_raw, &gz_raw); 41 | float gx = gx_raw * TO_RAD / 16.4; 42 | float gy = gy_raw * TO_RAD / 16.4; 43 | float gz = gz_raw * TO_RAD / 16.4; 44 | tm = millis(); 45 | if (imu_t + imu_to < tm) { 46 | tdelta = tm - imu_t; 47 | imu_t = tm; 48 | MadgwickAHRSupdateIMU(tdelta/1000.0, gx, gy, gz, (float)ax, (float)ay, (float)az); 49 | quat[0] = q0; quat[1] = q1; quat[2] = q2; quat[3] = q3; 50 | quat2Euler(&quat[0], &imu[0]); 51 | } 52 | tm = millis(); 53 | if (prn_t + prn_to < tm) { 54 | prn_t = tm; 55 | // Serial.print("x|y|z\t"); 56 | // Serial.print(ax); Serial.print("\t"); 57 | // Serial.print(ay); Serial.print("\t"); 58 | // Serial.println(az); 59 | Serial.print(imu[0]/TO_RAD); Serial.print("\t"); 60 | Serial.print(imu[1]/TO_RAD); Serial.print("\t"); 61 | Serial.println(imu[2]/TO_RAD); 62 | // Serial.print(gx); Serial.print("\t"); 63 | // Serial.print(gy); Serial.print("\t"); 64 | // Serial.println(gz); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sketches/Sensor.Comp_Filter_article/compl/compl.ino: -------------------------------------------------------------------------------- 1 | #include "I2Cdev.h" 2 | #include "MPU6050.h" 3 | 4 | #define TO_DEG 57.29577951308232087679815481410517033f 5 | #define T_OUT 20 6 | #define FK 0.1 7 | 8 | MPU6050 accelgyro; 9 | 10 | float angle_ax, angle_gx, angle_cpl; 11 | int dt = 0; 12 | long int t_next; 13 | 14 | float clamp(float v, float minv, float maxv){ 15 | if( v>maxv ) 16 | return maxv; 17 | else if( v= 0){ 44 | angle_ax = 90 - TO_DEG*acos(ay); 45 | } else { 46 | angle_ax = TO_DEG*acos(-ay) - 90; 47 | } 48 | angle_gx = angle_gx + gx * T_OUT/1000.0; 49 | 50 | angle_gx = angle_gx*(1-FK) + angle_ax*FK; 51 | 52 | Serial.print(angle_gx); 53 | Serial.print(", "); 54 | Serial.print(angle_ax); 55 | Serial.println(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /sketches/Sensor.Comp_Filter_article/compl_1/compl_1.ino: -------------------------------------------------------------------------------- 1 | #include "I2Cdev.h" 2 | #include "MPU6050.h" 3 | #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE 4 | #include "Wire.h" 5 | #endif 6 | 7 | #define TO_DEG 57.29577951308232087679815481410517033f 8 | #define T_OUT 20 // каждый 20 миллисекунд будем проводить вычисления 9 | #define P_OUT 50 // каждый 50 миллисекунд будем выводить данные 10 | #define FK 0.1 // коэффициент комплементарного фильтра 11 | 12 | MPU6050 accelgyro; 13 | 14 | float angle_ax, angle_gx, angle_cpl; 15 | int dt = 0; 16 | long int t_next, p_next; 17 | 18 | // функция, которая не даёт значению выйти за пределы 19 | float clamp(float v, float minv, float maxv){ 20 | if( v>maxv ) 21 | return maxv; 22 | else if( vmaxv ) 20 | return maxv; 21 | else if( v= 0){ 53 | angle_ax = 90 - TO_DEG*acos(ay); 54 | } else { 55 | angle_ax = TO_DEG*acos(-ay) - 90; 56 | } 57 | angle_gx = angle_gx + gx * T_OUT/1000.0; 58 | angle_cpl = angle_cpl + gx * T_OUT/1000.0; 59 | angle_cpl = angle_cpl*(1-FK) + angle_ax*FK; 60 | } 61 | 62 | t = millis(); 63 | if( p_next < t ){ 64 | p_next = t + P_OUT; 65 | Serial.print(angle_gx); 66 | Serial.print(", "); 67 | Serial.print(angle_ax); 68 | Serial.print(", "); 69 | Serial.print(angle_cpl); 70 | Serial.println(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /sketches/Sensor.DHT11_lesson/arduino-dht11-lcd/arduino-dht11-lcd.ino: -------------------------------------------------------------------------------- 1 | #include "DHT.h" 2 | #include 3 | 4 | LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 5 | 6 | #define DHTPIN 8 // what pin we're connected to 7 | 8 | #define DHTTYPE DHT11 // DHT 11 9 | //#define DHTTYPE DHT22 // DHT 22 (AM2302) 10 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 11 | 12 | DHT dht(DHTPIN, DHTTYPE); 13 | 14 | void setup() { 15 | lcd.begin(16, 2); 16 | lcd.print("RobotClass.ru"); 17 | dht.begin(); 18 | } 19 | 20 | void loop() { 21 | int h = dht.readHumidity(); 22 | int t = dht.readTemperature(); 23 | 24 | lcd.setCursor(0, 1); 25 | if (isnan(t) || isnan(h)) { 26 | lcd.print("Error"); 27 | } else { 28 | lcd.print("h="); 29 | lcd.print(h); 30 | lcd.print("%, t="); 31 | lcd.print(t); 32 | lcd.print("C"); 33 | } 34 | delay(100); 35 | } 36 | -------------------------------------------------------------------------------- /sketches/Sensor.DHT11_lesson/arduino-dht11/arduino-dht11.ino: -------------------------------------------------------------------------------- 1 | #include "DHT.h" 2 | 3 | #define DHTPIN 2 // what pin we're connected to 4 | 5 | #define DHTTYPE DHT11 // DHT 11 6 | //#define DHTTYPE DHT22 // DHT 22 (AM2302) 7 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 8 | 9 | DHT dht(DHTPIN, DHTTYPE); 10 | 11 | void setup() { 12 | Serial.begin(9600); 13 | Serial.println("Test DHT11"); 14 | 15 | dht.begin(); 16 | } 17 | 18 | void loop() { 19 | float h = dht.readHumidity(); 20 | float t = dht.readTemperature(); 21 | 22 | if (isnan(t) || isnan(h)) { 23 | Serial.println("Failed to read from DHT"); 24 | } else { 25 | Serial.print("Humidity: "); 26 | Serial.print(h); 27 | Serial.print(" %\t"); 28 | Serial.print("Temperature: "); 29 | Serial.print(t); 30 | Serial.println(" *C"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sketches/Sensor.DS18B20_lesson/ardu-ds18b20/ardu-ds18b20.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | OneWire ds(2); 4 | 5 | void setup() { 6 | Serial.begin(9600); 7 | } 8 | 9 | void loop() { 10 | byte i; 11 | byte present = 0; 12 | byte data[12]; 13 | byte addr[8]; 14 | float celsius; 15 | 16 | if ( !ds.search(addr)) { 17 | ds.reset_search(); 18 | delay(250); 19 | return; 20 | } 21 | 22 | ds.reset(); 23 | ds.select(addr); 24 | ds.write(0x44, 1); 25 | 26 | delay(1000); 27 | 28 | present = ds.reset(); 29 | ds.select(addr); 30 | ds.write(0xBE); 31 | 32 | for ( i = 0; i < 9; i++) { 33 | data[i] = ds.read(); 34 | } 35 | 36 | int16_t raw = (data[1] << 8) | data[0]; 37 | byte cfg = (data[4] & 0x60); 38 | if (cfg == 0x00) raw = raw & ~7; // точность 9-разрядов, 93,75 мс 39 | else if (cfg == 0x20) raw = raw & ~3; // точность 10-разрядов, 187,5 мс 40 | else if (cfg == 0x40) raw = raw & ~1; // точность 11-разрядов, 375 мс 41 | 42 | celsius = (float)raw / 16.0; 43 | Serial.print("t="); 44 | Serial.println(celsius); 45 | } 46 | -------------------------------------------------------------------------------- /sketches/Sensor.LPF_lesson/lpf_mpu6050/lpf_mpu6050.ino: -------------------------------------------------------------------------------- 1 | #include "I2Cdev.h" 2 | #include "MPU6050.h" 3 | 4 | #define TO_DEG 57.29577951308232087679815481410517033f 5 | #define T_OUT 20 6 | #define FK 0.5 7 | 8 | MPU6050 accelgyro; 9 | 10 | float ay,ayf; 11 | int dt = 0; 12 | long int t_next; 13 | 14 | void setup() { 15 | Serial.begin(9600); 16 | accelgyro.initialize(); 17 | Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); 18 | } 19 | 20 | void loop() { 21 | long int t = millis(); 22 | if( t_next < t ){ 23 | int16_t ax_raw, ay_raw, az_raw, gx_raw, gy_raw, gz_raw; 24 | float ay; 25 | 26 | accelgyro.getMotion6(&ax_raw, &ay_raw, &az_raw, &gx_raw, &gy_raw, &gz_raw); 27 | 28 | ay = ay_raw / 4096.0; 29 | ayf = ayf*(1-FK) + ay*FK; 30 | 31 | 32 | Serial.print(ay); 33 | Serial.print(", "); 34 | Serial.print(ayf); 35 | Serial.println(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sketches/Sensor.LPF_lesson/lpf_pot/lpf_pot.ino: -------------------------------------------------------------------------------- 1 | const byte potPin = A5; 2 | const float K = 1.0; 3 | 4 | float val = 0; 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | pinMode( potPin, INPUT ); 9 | } 10 | 11 | void loop() { 12 | int pot = analogRead( potPin ); 13 | val = val*(1-K) + pot*K; 14 | Serial.println(val); 15 | delay(20); 16 | } 17 | -------------------------------------------------------------------------------- /sketches/Sensor.LPF_lesson/lpf_pot_diff/lpf_pot_diff.ino: -------------------------------------------------------------------------------- 1 | const byte potPin = A5; 2 | const float K = 0.1; 3 | 4 | float val = 0; 5 | 6 | void setup() { 7 | Serial.begin(9600); 8 | pinMode( potPin, INPUT ); 9 | } 10 | 11 | void loop() { 12 | int pot = analogRead( potPin ); 13 | val = val*(1-K) + pot*K; 14 | Serial.print(pot); 15 | Serial.print(","); 16 | Serial.println(int(val)); 17 | delay(20); 18 | } 19 | -------------------------------------------------------------------------------- /sketches/Sensor.MLX90620_lesson/MLX90620_Example/MLX90620_registers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Register values from Datasheet_90620.pdf dated 19 September 2012 3 | */ 4 | 5 | //Yes really, it's not 0x60, the EEPROM has its own address (I've never seen this before) 6 | #define MLX90620_EEPROM_WRITE 0xA0 7 | #define MLX90620_EEPROM_READ 0xA1 8 | 9 | //The sensor's I2C address is 0x60. So 0b.1100.000W becomes 0xC0 10 | #define MLX90620_WRITE 0xC0 11 | #define MLX90620_READ 0xC1 12 | 13 | //These are commands 14 | #define CMD_READ_REGISTER 0x02 15 | 16 | //Begin registers 17 | 18 | #define CAL_ACP 0xD4 19 | #define CAL_BCP 0xD5 20 | #define CAL_alphaCP_L 0xD6 21 | #define CAL_alphaCP_H 0xD7 22 | #define CAL_TGC 0xD8 23 | #define CAL_BI_SCALE 0xD9 24 | 25 | #define VTH_L 0xDA 26 | #define VTH_H 0xDB 27 | #define KT1_L 0xDC 28 | #define KT1_H 0xDD 29 | #define KT2_L 0xDE 30 | #define KT2_H 0xDF 31 | 32 | //Common sensitivity coefficients 33 | #define CAL_A0_L 0xE0 34 | #define CAL_A0_H 0xE1 35 | #define CAL_A0_SCALE 0xE2 36 | #define CAL_DELTA_A_SCALE 0xE3 37 | #define CAL_EMIS_L 0xE4 38 | #define CAL_EMIS_H 0xE5 39 | 40 | //KSTA 41 | 42 | //Config register = 0xF5-F6 43 | 44 | #define OSC_TRIM_VALUE 0xF7 45 | 46 | //Bits within configuration register 0x92 47 | 48 | #define POR_TEST 10 49 | 50 | -------------------------------------------------------------------------------- /sketches/Sensor.MLX90620_lesson/MLX90620_alphaCalculator/MLX90620_registers.h: -------------------------------------------------------------------------------- 1 | /* 2 | Register values from Datasheet_90620.pdf dated 19 September 2012 3 | */ 4 | 5 | //Yes really, it's not 0x60, the EEPROM has its own address (I've never seen this before) 6 | #define MLX90620_EEPROM_WRITE 0xA0 7 | #define MLX90620_EEPROM_READ 0xA1 8 | 9 | //The sensor's I2C address is 0x60. So 0b.1100.000W becomes 0xC0 10 | #define MLX90620_WRITE 0xC0 11 | #define MLX90620_READ 0xC1 12 | 13 | //These are commands 14 | #define CMD_READ_REGISTER 0x02 15 | 16 | //Begin registers 17 | 18 | #define CAL_ACP 0xD4 19 | #define CAL_BCP 0xD5 20 | #define CAL_alphaCP_L 0xD6 21 | #define CAL_alphaCP_H 0xD7 22 | #define CAL_TGC 0xD8 23 | #define CAL_BI_SCALE 0xD9 24 | 25 | #define VTH_L 0xDA 26 | #define VTH_H 0xDB 27 | #define KT1_L 0xDC 28 | #define KT1_H 0xDD 29 | #define KT2_L 0xDE 30 | #define KT2_H 0xDF 31 | 32 | //Common sensitivity coefficients 33 | #define CAL_A0_L 0xE0 34 | #define CAL_A0_H 0xE1 35 | #define CAL_A0_SCALE 0xE2 36 | #define CAL_DELTA_A_SCALE 0xE3 37 | #define CAL_EMIS_L 0xE4 38 | #define CAL_EMIS_H 0xE5 39 | 40 | //KSTA 41 | 42 | //Config register = 0xF5-F6 43 | 44 | #define OSC_TRIM_VALUE 0xF7 45 | 46 | //Bits within configuration register 0x92 47 | 48 | #define POR_TEST 10 49 | 50 | -------------------------------------------------------------------------------- /sketches/Sensor.MPU6050_lesson/mpu6050/mpu6050.ino: -------------------------------------------------------------------------------- 1 | #include "I2Cdev.h" 2 | #include "MPU6050.h" 3 | 4 | #define TO_DEG 57.29577951308232087679815481410517033f 5 | #define T_OUT 20 6 | 7 | MPU6050 accelgyro; 8 | 9 | float angle_ax; 10 | long int t_next; 11 | 12 | float clamp(float v, float minv, float maxv){ 13 | if( v>maxv ) 14 | return maxv; 15 | else if( v= 0){ 40 | angle_ax = 90 - TO_DEG*acos(ay); 41 | } else { 42 | angle_ax = TO_DEG*acos(-ay) - 90; 43 | } 44 | 45 | Serial.println(angle_ax); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sketches/Sensor.MPU6050_lesson/mpu6050_raw/mpu6050_raw.ino: -------------------------------------------------------------------------------- 1 | #include "I2Cdev.h" 2 | #include "MPU6050.h" 3 | 4 | #define T_OUT 50 5 | 6 | MPU6050 accelgyro; 7 | 8 | unsigned long int t_next; 9 | 10 | void setup() { 11 | Serial.begin(9600); 12 | accelgyro.initialize(); 13 | Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); 14 | } 15 | 16 | void loop() { 17 | long int t = millis(); 18 | if( t_next < t ){ 19 | int16_t ax_raw, ay_raw, az_raw, gx_raw, gy_raw, gz_raw; 20 | 21 | t_next = t + T_OUT; 22 | accelgyro.getMotion6(&ax_raw, &ay_raw, &az_raw, &gx_raw, &gy_raw, &gz_raw); 23 | 24 | Serial.print(ax_raw); // вывод в порт проекции ускорения на ось Y 25 | Serial.print(" - "); 26 | Serial.println(ay_raw); // вывод в порт проекции ускорения на ось Y 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/MadgwickAHRS/MadgwickAHRS.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Madgwick AHRS Arduino library 3 | * Math author: Sebastian Madgwick 4 | * Written by Oleg Evsegneev for RobotClass. 5 | */ 6 | extern volatile float beta; 7 | extern volatile float q0, q1, q2, q3; 8 | 9 | void MadgwickAHRSupdate(float tdelta, float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz); 10 | void MadgwickAHRSupdateIMU(float tdelta, float gx, float gy, float gz, float ax, float ay, float az); 11 | float invSqrt(float x); 12 | void quat2Euler( float q[4], float e[3] ); 13 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/MadgwickAHRS/README.md: -------------------------------------------------------------------------------- 1 | # MadgwickAHRS 2 | Madgwick AHRS Arduino library 3 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/MadgwickAHRS/examples/MPU6050Test/MPU6050Test.ino: -------------------------------------------------------------------------------- 1 | #include "I2Cdev.h" 2 | #include "MPU6050.h" 3 | #include "MadgwickAHRS.h" 4 | 5 | #define TO_RAD 0.01745329252f 6 | 7 | MPU6050 accelgyro; 8 | 9 | unsigned long tm, imu_t, prn_t; 10 | const unsigned int imu_to = 20; 11 | const unsigned int prn_to = 100; 12 | 13 | float tdelta; 14 | int16_t ax, ay, az; 15 | int16_t gx_raw, gy_raw, gz_raw; 16 | 17 | float imu[3]; 18 | float quat[4]; 19 | float e[3]; 20 | 21 | void setup() { 22 | Serial.begin(9600); 23 | Serial.println("Initializing I2C devices..."); 24 | accelgyro.initialize(); // инициализация датчиков 25 | Serial.println("Testing device connections..."); 26 | Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); 27 | } 28 | 29 | void loop() { 30 | accelgyro.getMotion6(&ax, &ay, &az, &gx_raw, &gy_raw, &gz_raw); 31 | 32 | // преобразуем сырые данные гироскопа в рад/с 33 | float gx = gx_raw * TO_RAD / 131.0; 34 | float gy = gy_raw * TO_RAD / 131.0; 35 | float gz = gz_raw * TO_RAD / 131.0; 36 | 37 | // каждые 20мс вычисляем углы наклона 38 | tm = millis(); 39 | if (imu_t + imu_to < tm) { 40 | tdelta = tm - imu_t; // вычисляем дельту времени в миллисекундах 41 | imu_t = tm; 42 | // вызываем алгоритм фильтра и передаем туда: 43 | // - дельту времени в секундах 44 | // - данные гироскопа в рад/с 45 | // - сырые данные акселерометра 46 | MadgwickAHRSupdateIMU(tdelta/1000.0, gx, gy, gz, (float)ax, (float)ay, (float)az); 47 | quat[0] = q0; quat[1] = q1; quat[2] = q2; quat[3] = q3; 48 | quat2Euler(&quat[0], &imu[0]); // преобразуем кватернион в углы Эйлера 49 | } 50 | 51 | // каждые 100мс добавляем новую точку графика 52 | tm = millis(); 53 | if (prn_t + prn_to < tm) { 54 | prn_t = tm; 55 | Serial.print(imu[0]/TO_RAD); Serial.print("\t"); 56 | Serial.print(imu[1]/TO_RAD); Serial.print("\t"); 57 | Serial.println(imu[2]/TO_RAD); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/MadgwickAHRS/keywords.txt: -------------------------------------------------------------------------------- 1 | ########################################### 2 | # Syntax Coloring Map For Madgwick AHRS#### 3 | ########################################### 4 | 5 | ########################################### 6 | # Datatypes (KEYWORD1) 7 | ########################################### 8 | 9 | MadgwickAHRS KEYWORD1 10 | 11 | ########################################### 12 | # Methods and Functions (KEYWORD2) 13 | ########################################### 14 | MadgwickAHRSupdate KEYWORD2 15 | MadgwickAHRSupdateIMU KEYWORD2 16 | invSqrt KEYWORD2 17 | quat2Euler KEYWORD2 18 | ########################################### 19 | # Constants (LITERAL1) 20 | ########################################### 21 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/MadgwickAHRS/library.properties: -------------------------------------------------------------------------------- 1 | name=MadgwickAHRS 2 | version=0.1 3 | author=Oleg Evsegneev 4 | maintainer=Oleg Evsegneev 5 | sentence=A library for Madgwick AHRS. 6 | paragraph= The library allows to apply Madgwick AHRS filtering math to raw accelerometer and gyroscope data to calculate position quaternion. THIS LIBRARY MIGHT NOT BE COMPATIBLE WITH EXISTING SKETCHES. 7 | category=Other 8 | url=https://github.com/robotclass/RobotClass-MadgwickAHRS 9 | architectures=avr 10 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/imu_madgwick/Madgwick.h: -------------------------------------------------------------------------------- 1 | extern volatile float beta; 2 | extern volatile float q0, q1, q2, q3; 3 | 4 | void MadgwickAHRSupdate(float tdelta, float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz); 5 | void MadgwickAHRSupdateIMU(float tdelta, float gx, float gy, float gz, float ax, float ay, float az); 6 | float invSqrt(float x); 7 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/imu_madgwick/readme.txt: -------------------------------------------------------------------------------- 1 | Sensors: 2 | - adxl345 3 | - l3g4200 4 | - hmc883l -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/imu_madgwick_z/Madgwick.h: -------------------------------------------------------------------------------- 1 | extern volatile float beta; 2 | extern volatile float q0, q1, q2, q3; 3 | 4 | void MadgwickAHRSupdate(float tdelta, float gx, float gy, float gz, float ax, float ay, float az, float mx, float my, float mz); 5 | void MadgwickAHRSupdateIMU(float tdelta, float gx, float gy, float gz, float ax, float ay, float az); 6 | float invSqrt(float x); 7 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/imu_madgwick_z/utils.h: -------------------------------------------------------------------------------- 1 | void quat_2_euler( float q[4], float e[3] ){ 2 | //double sqw = q[0]*q[0]; 3 | double sqx = q[1]*q[1]; 4 | double sqy = q[2]*q[2]; 5 | double sqz = q[3]*q[3]; 6 | 7 | e[0] = atan2f(2.f * (q[2]*q[3] + q[1]*q[0]), 1 - 2.f * (sqx + sqy));// -sqx - sqy + sqz + sqw); 8 | e[1] = asinf(-2.f * (q[1]*q[3] - q[2]*q[0])); 9 | e[2] = atan2f(2.f * (q[1]*q[2] + q[3]*q[0]), 1 - 2.f * (sqy + sqz));//sqx - sqy - sqz + sqw); 10 | } 11 | 12 | float deadband(float v, float db){ 13 | if(abs(v) < db) { 14 | return 0.0f; 15 | } else if(v > 0){ 16 | return v - db; 17 | } else if(v < 0){ 18 | return v + db; 19 | } 20 | return 0; 21 | } 22 | -------------------------------------------------------------------------------- /sketches/Sensor.Madgwick_article/madgwick_test/madgwick_test.ino: -------------------------------------------------------------------------------- 1 | #include "I2Cdev.h" 2 | #include "MPU6050.h" 3 | #include "MadgwickAHRS.h" 4 | 5 | #define TO_RAD 0.01745329252f 6 | 7 | MPU6050 accelgyro; 8 | 9 | unsigned long tm, imu_t, prn_t; 10 | const unsigned int imu_to = 20; 11 | const unsigned int prn_to = 100; 12 | 13 | float tdelta; 14 | int16_t ax, ay, az; 15 | int16_t gx_raw, gy_raw, gz_raw; 16 | 17 | float imu[3]; 18 | float quat[4]; 19 | float e[3]; 20 | 21 | void setup() { 22 | Serial.begin(9600); 23 | Serial.println("Initializing I2C devices..."); 24 | accelgyro.initialize(); // инициализация датчиков 25 | Serial.println("Testing device connections..."); 26 | Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); 27 | } 28 | 29 | void loop() { 30 | accelgyro.getMotion6(&ax, &ay, &az, &gx_raw, &gy_raw, &gz_raw); 31 | 32 | // преобразуем сырые данные гироскопа в рад/с 33 | float gx = gx_raw * TO_RAD / 131.0; 34 | float gy = gy_raw * TO_RAD / 131.0; 35 | float gz = gz_raw * TO_RAD / 131.0; 36 | 37 | // каждые 20мс вычисляем углы наклона 38 | tm = millis(); 39 | if (imu_t + imu_to < tm) { 40 | tdelta = tm - imu_t; // вычисляем дельту времени в миллисекундах 41 | imu_t = tm; 42 | // вызываем алгоритм фильтра и передаем туда: 43 | // - дельту времени в секундах 44 | // - данные гироскопа в рад/с 45 | // - сырые данные акселерометра 46 | MadgwickAHRSupdateIMU(tdelta/1000.0, gx, gy, gz, (float)ax, (float)ay, (float)az); 47 | quat[0] = q0; quat[1] = q1; quat[2] = q2; quat[3] = q3; 48 | quat2Euler(&quat[0], &imu[0]); // преобразуем кватернион в углы Эйлера 49 | } 50 | 51 | // каждые 100мс добавляем новую точку графика 52 | tm = millis(); 53 | if (prn_t + prn_to < tm) { 54 | prn_t = tm; 55 | Serial.print(imu[0]/TO_RAD); Serial.print("\t"); 56 | Serial.print(imu[1]/TO_RAD); Serial.print("\t"); 57 | Serial.println(imu[2]/TO_RAD); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sketches/Sensor.ROC.BME280_lesson/BME280_test/BME280_test.ino: -------------------------------------------------------------------------------- 1 | //#include 2 | //#include 3 | //#include 4 | #include 5 | 6 | Adafruit_BME280 bme; 7 | 8 | void setup() { 9 | Serial.begin(9600); 10 | bme.begin(); 11 | } 12 | 13 | void loop() { 14 | // вывод температуры в градусах Цельсия 15 | Serial.print("t = "); 16 | Serial.print(bme.readTemperature()); 17 | Serial.println(" *C"); 18 | 19 | // вывод атмосферного давления в гектопаскалях hPa 20 | Serial.print("p = "); 21 | 22 | Serial.print(bme.readPressure() / 100.0F); 23 | Serial.println(" hPa"); 24 | 25 | // вывод высоты над уровнем моря в метрах 26 | // 1013.25 - давление на уровне моря 27 | Serial.print("alt = "); 28 | Serial.print(bme.readAltitude(1013.25)); 29 | Serial.println(" m"); 30 | 31 | // вывод влажности в процентах 32 | Serial.print("h = "); 33 | Serial.print(bme.readHumidity()); 34 | Serial.println(" %"); 35 | 36 | Serial.println(); 37 | 38 | delay(1000); 39 | } 40 | -------------------------------------------------------------------------------- /sketches/Sensor.ROC.BMP280_lesson/bmp280test/bmp280test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | Adafruit_BMP280 bmp; 4 | 5 | void setup() { 6 | Serial.begin(9600); 7 | 8 | if (!bmp.begin()) { 9 | Serial.println("Error!"); 10 | while (1); 11 | } 12 | } 13 | 14 | void loop() { 15 | Serial.print("TEMP = "); 16 | Serial.print(bmp.readTemperature()); 17 | Serial.println(" *C"); 18 | 19 | Serial.print("PRES = "); 20 | Serial.print(bmp.readPressure()); 21 | Serial.println(" Pa"); 22 | 23 | Serial.print("ALT = "); 24 | Serial.print(bmp.readAltitude(1013.25)); 25 | Serial.println(" m"); 26 | 27 | Serial.println(); 28 | delay(2000); 29 | } 30 | -------------------------------------------------------------------------------- /sketches/Sensor.ROC.BMP280_lesson/bmp280testSPI/bmp280testSPI.ino: -------------------------------------------------------------------------------- 1 | //#include 2 | //#include 3 | //#include 4 | #include 5 | 6 | #define BMP_SCK 13 7 | #define BMP_MISO 12 8 | #define BMP_MOSI 11 9 | #define BMP_CS 10 10 | 11 | //Adafruit_BMP280 bmp(BMP_CS); // при использовании аппаратного SPI 12 | Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK); 13 | 14 | void setup() { 15 | Serial.begin(9600); 16 | 17 | if (!bmp.begin()) { 18 | Serial.println("Error!"); 19 | while (1); 20 | } 21 | } 22 | 23 | void loop() { 24 | Serial.print("T = "); 25 | Serial.print(bmp.readTemperature()); 26 | Serial.println(" *C"); 27 | 28 | Serial.print("P = "); 29 | Serial.print(bmp.readPressure()); 30 | Serial.println(" Pa"); 31 | 32 | Serial.print("A = "); 33 | Serial.print(bmp.readAltitude(1013.25)); 34 | Serial.println(" m"); 35 | 36 | Serial.println(); 37 | delay(2000); 38 | } 39 | -------------------------------------------------------------------------------- /sketches/Sensor.TSL1401_lesson/TSL1401_SFMonitor/TSL1401_SFMonitor.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static const byte PACKET_SIZE = 128; 4 | static const byte VALUE_SIZE = 1; 5 | static const boolean SEPARATE_VALUES = false; 6 | 7 | const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0); 8 | const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); 9 | int CLKpin = 4; // CLK - Clock 10 | int SIpin = 5; // SI - Serial input 11 | int AOpin = A0; // AO - Analog output 12 | int IntArray[128]; 13 | char ptxt[128 + 1]; 14 | 15 | SerialFlow rd(&Serial); 16 | 17 | void setup() { 18 | rd.setPacketFormat(VALUE_SIZE, PACKET_SIZE, SEPARATE_VALUES); 19 | rd.begin(115200); 20 | 21 | pinMode(CLKpin, OUTPUT); 22 | pinMode(SIpin, OUTPUT); 23 | 24 | // ускоряем АЦП в 4 раза 25 | ADCSRA &= ~PS_128; 26 | ADCSRA |= PS_32; // теперь одно АЦП преобразование займет ~30 мкс 27 | 28 | analogReference(DEFAULT); 29 | 30 | // Установка всех GPIO в LOW: 31 | for( int i=0; i< 14; i++ ){ 32 | digitalWrite(i, LOW); 33 | } 34 | 35 | // Чистка регистра сенсора с помощью серии синхроимпульсов 36 | //for(int i=0;i<128;i++){ 37 | // ClockPulse(); 38 | //} 39 | 40 | // Запуск первого измерения 41 | digitalWrite(SIpin, HIGH); 42 | ClockPulse(); 43 | digitalWrite(SIpin, LOW); 44 | 45 | // Пока идет измерение, чистим содержимое регистра датчика 46 | for(int i=0;i< 260;i++){ 47 | ClockPulse(); 48 | } 49 | } 50 | 51 | void loop(){ 52 | // Остановка измерения N-1, и запуск измерения N путем отправки импульса SI 53 | digitalWrite(SIpin, HIGH); 54 | ClockPulse(); 55 | digitalWrite(SIpin, LOW); 56 | 57 | // Чтение 128 пикселей, полученных во время измерения N-1 58 | for(int i=0; i < 128; i++){ 59 | delayMicroseconds(20); // пауза для фиксации значения на АЦП 60 | IntArray[i] = analogRead(AOpin); 61 | ClockPulse(); 62 | } 63 | 64 | // Остановка измерения N, и запуск измерения N+1 путем отправки импульса SI 65 | digitalWrite(SIpin, HIGH); 66 | ClockPulse(); 67 | digitalWrite(SIpin, LOW); 68 | 69 | // Отправка вектора значений через UART 70 | for(int i=0; i<128; i++){ 71 | rd.setPacketValue(IntArray[i]/4); 72 | } 73 | rd.sendPacket(); 74 | 75 | // 76 | for(int i = 0; i < 260; i++){ 77 | ClockPulse(); 78 | } 79 | 80 | // Время одного измерения составляет 3мс. Чтобы увеличить время интеграции можно добавить паузу. 81 | // delay(15); 82 | } 83 | 84 | // Функция, генерирующая синхроимпульс 85 | void ClockPulse(){ 86 | delayMicroseconds(1); 87 | digitalWrite(CLKpin, HIGH); 88 | digitalWrite(CLKpin, LOW); 89 | } 90 | -------------------------------------------------------------------------------- /sketches/Sensor.TSL1401_lesson/TSL1401_SFMonitor_oneshot/TSL1401_SFMonitor_oneshot.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | static const byte PACKET_SIZE = 128; 4 | static const byte VALUE_SIZE = 1; 5 | static const boolean SEPARATE_VALUES = false; 6 | 7 | const unsigned char PS_32 = (1 << ADPS2) | (1 << ADPS0); 8 | const unsigned char PS_128 = (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); 9 | int CLKpin = 4; // CLK - Clock 10 | int SIpin = 5; // SI - Serial input 11 | int AOpin = A0; // AO - Analog output 12 | int IntArray[128]; 13 | char ptxt[128 + 1]; 14 | 15 | SerialFlow rd(&Serial); 16 | 17 | void setup() { 18 | rd.setPacketFormat(VALUE_SIZE, PACKET_SIZE, SEPARATE_VALUES); 19 | rd.begin(115200); 20 | 21 | pinMode(CLKpin, OUTPUT); 22 | pinMode(SIpin, OUTPUT); 23 | 24 | // ускоряем АЦП в 4 раза 25 | ADCSRA &= ~PS_128; 26 | ADCSRA |= PS_32; // теперь одно АЦП преобразование займет ~30 мкс 27 | 28 | analogReference(DEFAULT); 29 | 30 | // Установка всех GPIO в LOW: 31 | for( int i=0; i< 14; i++ ){ 32 | digitalWrite(i, LOW); 33 | } 34 | 35 | // Запуск первого измерения 36 | digitalWrite(SIpin, HIGH); 37 | ClockPulse(); 38 | digitalWrite(SIpin, LOW); 39 | 40 | // Пока идет измерение, чистим содержимое регистра датчика 41 | for(int i=0;i< 260;i++){ 42 | ClockPulse(); 43 | } 44 | } 45 | 46 | void loop(){ 47 | // Запуск нового измерения 48 | digitalWrite(SIpin, HIGH); 49 | ClockPulse(); 50 | digitalWrite(SIpin, LOW); 51 | 52 | // Чистка регистра датчика от мусора 53 | for(int i = 0; i < 128; i++){ 54 | ClockPulse(); 55 | } 56 | 57 | // Экспозиция 3мс 58 | delay(3); 59 | 60 | // Запуск сбора данных 61 | digitalWrite(SIpin, HIGH); 62 | ClockPulse(); 63 | digitalWrite(SIpin, LOW); 64 | 65 | // Чтение 128 пикселей 66 | for(int i=0; i < 128; i++){ 67 | delayMicroseconds(20); // пауза для фиксации значения на АЦП 68 | IntArray[i] = analogRead(AOpin); 69 | ClockPulse(); 70 | } 71 | 72 | // Отправка вектора значений через UART 73 | for(int i=0; i<128; i++){ 74 | rd.setPacketValue(IntArray[i]/4); 75 | } 76 | rd.sendPacket(); 77 | 78 | // Здесь можем выполнять основной алгоритм 79 | // ... 80 | } 81 | 82 | // Функция, генерирующая синхроимпульс 83 | void ClockPulse(){ 84 | delayMicroseconds(1); 85 | digitalWrite(CLKpin, HIGH); 86 | digitalWrite(CLKpin, LOW); 87 | } 88 | -------------------------------------------------------------------------------- /sketches/Sensor.TSL2561_lesson/tsl2561/tsl2561.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include "TSL2561.h" 3 | 4 | TSL2561 tsl(TSL2561_ADDR_FLOAT); 5 | 6 | void setup(void) { 7 | Serial.begin(9600); 8 | 9 | tsl.begin(); 10 | 11 | tsl.setGain(TSL2561_GAIN_16X); 12 | 13 | tsl.setTiming(TSL2561_INTEGRATIONTIME_402MS); //13, 101, 402 14 | } 15 | 16 | void loop(void) { 17 | // This can take 13-402 milliseconds! Uncomment whichever of the following you want to read 18 | uint16_t x = tsl.getLuminosity(TSL2561_VISIBLE); 19 | //uint16_t x = tsl.getLuminosity(TSL2561_FULLSPECTRUM); 20 | //uint16_t x = tsl.getLuminosity(TSL2561_INFRARED); 21 | 22 | 23 | // More advanced data read example. Read 32 bits with top 16 bits IR, bottom 16 bits full spectrum 24 | uint32_t lum = tsl.getFullLuminosity(); 25 | uint16_t ir, full; 26 | ir = lum >> 16; 27 | full = lum & 0xFFFF; 28 | 29 | Serial.print("Full: "); 30 | Serial.print(full); 31 | Serial.print(", Visible: "); 32 | Serial.print(full - ir); 33 | Serial.print(", Lux: "); 34 | Serial.println(tsl.calculateLux(full, ir)); 35 | 36 | delay(100); 37 | } 38 | -------------------------------------------------------------------------------- /sketches/Sensor.Thermistor_NTC_lesson/thermistor-100k-t/thermistor-100k-t.ino: -------------------------------------------------------------------------------- 1 | #define B 3950 // B-коэффициент 2 | #define SERIAL_R 102000 // сопротивление последовательного резистора, 102 кОм 3 | #define THERMISTOR_R 100000 // номинальное сопротивления термистора, 100 кОм 4 | #define NOMINAL_T 25 // номинальная температура (при которой TR = 100 кОм) 5 | 6 | const byte tempPin = A0; 7 | 8 | void setup() { 9 | Serial.begin( 9600 ); 10 | pinMode( tempPin, INPUT ); 11 | } 12 | 13 | void loop() { 14 | int t = analogRead( tempPin ); 15 | float tr = 1023.0 / t - 1; 16 | tr = SERIAL_R / tr; 17 | Serial.print("R="); 18 | Serial.print(tr); 19 | Serial.print(", t="); 20 | 21 | float steinhart; 22 | steinhart = tr / THERMISTOR_R; // (R/Ro) 23 | steinhart = log(steinhart); // ln(R/Ro) 24 | steinhart /= B; // 1/B * ln(R/Ro) 25 | steinhart += 1.0 / (NOMINAL_T + 273.15); // + (1/To) 26 | steinhart = 1.0 / steinhart; // Invert 27 | steinhart -= 273.15; 28 | Serial.println(steinhart); 29 | 30 | delay(100); 31 | } 32 | -------------------------------------------------------------------------------- /sketches/Sensor.Thermistor_NTC_lesson/thermistor-100k-ta/thermistor-100k-ta.ino: -------------------------------------------------------------------------------- 1 | #define B 3950 // B-коэффициент 2 | #define SERIAL_R 102000 // сопротивление последовательного резистора, 102 кОм 3 | #define THERMISTOR_R 100000 // номинальное сопротивления термистора, 100 кОм 4 | #define NOMINAL_T 25 // номинальная температура (при которой TR = 100 кОм) 5 | 6 | const byte tempPin = A0; 7 | 8 | void setup() { 9 | Serial.begin( 9600 ); 10 | pinMode( tempPin, INPUT ); 11 | } 12 | 13 | void loop() { 14 | float t; 15 | for( int i=0; i<10; i++ ){ 16 | t += analogRead( tempPin ); 17 | delay(10); 18 | } 19 | t = t / 10; 20 | 21 | float tr = 1023.0 / t - 1; 22 | tr = SERIAL_R / tr; 23 | Serial.print("R="); 24 | Serial.print(tr); 25 | Serial.print(", t="); 26 | 27 | float steinhart; 28 | steinhart = tr / THERMISTOR_R; // (R/Ro) 29 | steinhart = log(steinhart); // ln(R/Ro) 30 | steinhart /= B; // 1/B * ln(R/Ro) 31 | steinhart += 1.0 / (NOMINAL_T + 273.15); // + (1/To) 32 | steinhart = 1.0 / steinhart; // Invert 33 | steinhart -= 273.15; 34 | Serial.println(steinhart); 35 | 36 | } 37 | -------------------------------------------------------------------------------- /sketches/Sensor.Thermistor_NTC_lesson/thermistor-100k/thermistor-100k.ino: -------------------------------------------------------------------------------- 1 | #define SERIAL_R 102000 // сопротивление последовательного резистора, 102 кОм 2 | 3 | const byte tempPin = A0; 4 | 5 | void setup() { 6 | Serial.begin( 9600 ); 7 | pinMode( tempPin, INPUT ); 8 | } 9 | 10 | void loop() { 11 | int t = analogRead( tempPin ); 12 | float tr = 1023.0 / t - 1; 13 | tr = SERIAL_R / tr; 14 | Serial.println(tr); 15 | delay(100); 16 | } 17 | -------------------------------------------------------------------------------- /sketches/Sound/bit8mario/bit8mario.ino: -------------------------------------------------------------------------------- 1 | int speaker = 11; 2 | long vel = 20000; 3 | 4 | #define C 1911 5 | #define C1 1804 6 | #define D 1703 7 | #define Eb 1607 8 | #define E 1517 9 | #define F 1432 10 | #define F1 1352 11 | #define G 1276 12 | #define Ab 1204 13 | #define A 1136 14 | #define Bb 1073 15 | #define B 1012 16 | #define c 955 17 | #define c1 902 18 | #define d 851 19 | #define eb 803 20 | #define e 758 21 | #define f 716 22 | #define f1 676 23 | #define g 638 24 | #define ab 602 25 | #define a 568 26 | #define bb 536 27 | #define b 506 28 | 29 | #define p 0 30 | 31 | void setup() { 32 | Serial.begin(9600); 33 | pinMode(speaker, OUTPUT); 34 | delay(2000); 35 | } 36 | 37 | int melod[] = {e, e, e, c, e, g, G, c, G, E, A, B, Bb, A, G, e, g, a, f, g, e, c, d, B, c}; 38 | int ritmo[] = {6, 12, 12, 6, 12, 24, 24, 18, 18, 18, 12, 12, 6, 12, 8, 8, 8, 12, 6, 12, 12, 6, 6, 6, 12}; 39 | 40 | void loop() { 41 | for (int i=0; i<26; i++) { 42 | int tom = melod[i]; 43 | int tempo = ritmo[i]; 44 | 45 | long tvalue = tempo * vel; 46 | 47 | tocar(tom, tvalue); 48 | 49 | delayMicroseconds(1000); //pausa entre notas! 50 | //Serial.print(i); 51 | //Serial.print(" "); 52 | } 53 | delay(1000); 54 | } 55 | 56 | void tocar(int tom, long tempo_value) { 57 | long tempo_gasto = 0; 58 | while (tempo_gasto < tempo_value) { 59 | digitalWrite(speaker, HIGH); 60 | delayMicroseconds(tom / 2); 61 | 62 | digitalWrite(speaker, LOW); 63 | delayMicroseconds(tom/2); 64 | 65 | tempo_gasto += tom; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /sketches/Sound/wav/wav.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #define SD_ChipSelectPin 10 3 | #include 4 | #include 5 | 6 | TMRpcm tmrpcm; // create an object for use in this sketch 7 | 8 | int ledPin = 8; 9 | 10 | void blink(int count){ 11 | for(int i=0; i= next_time_1 ){ // если текущее время превысило намеченное время, то 25 | next_time_1 = now_time + timeout_1; // вычисляем время следующего переключения 26 | led_state_1 = !led_state_1; // меняем состояние на противоположное 27 | digitalWrite(ledPin_1, led_state_1); // зажигаем или гасим светодиод 28 | } 29 | 30 | now_time = millis(); 31 | if( now_time >= next_time_2 ){ 32 | next_time_2 = now_time + timeout_2; 33 | led_state_2 = !led_state_2; 34 | digitalWrite(ledPin_2, led_state_2); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sketches/Timeout_lesson/Blink_timeout/Blink_timeout.ino: -------------------------------------------------------------------------------- 1 | const int ledPin = 2; 2 | 3 | int next_time; 4 | int timeout = 500; // половина периода мигания 5 | int led_state = 0; // начальное состояние светодиода - выключен 6 | 7 | void setup() { 8 | pinMode(ledPin, OUTPUT); 9 | 10 | digitalWrite(ledPin, led_state); // гасим светодиод 11 | next_time = millis() + timeout; // вычисляем время следующего переключения 12 | } 13 | 14 | void loop() { 15 | int now_time = millis(); // текущее время 16 | if( now_time >= next_time ){ // если текущее время превысило намеченное время, то 17 | next_time = now_time + timeout; // вычисляем время следующего переключения 18 | led_state = !led_state; // меняем состояние на противоположное 19 | digitalWrite(ledPin, led_state); // зажигаем или гасим светодиод 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sketches/blocks_servo_sweep/blocks_servo_sweep.ino: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | Servo servos[13]; 5 | 6 | void setup() 7 | { 8 | 9 | } 10 | 11 | 12 | void loop() 13 | { 14 | servos[8].attach(8); 15 | servos[8].write((map(analogRead(A0), 0, 1024, 0, 180))); 16 | delay(50); 17 | 18 | } 19 | -------------------------------------------------------------------------------- /sketches/esc_test_2/esc_test_2.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define SERVO_MAX 2000 4 | #define SERVO_MIN 1000 5 | #define SERVO_D 1000 6 | 7 | Servo ss; 8 | 9 | void blip(byte count){ 10 | for( byte c=0; c=0; i-=5){ 42 | setPwr(i); 43 | delay(300); 44 | } 45 | } 46 | 47 | void loop() { 48 | return; 49 | } 50 | -------------------------------------------------------------------------------- /sketches/heart/heart.ino: -------------------------------------------------------------------------------- 1 | //#define INVERSED 2 | 3 | void setup() { 4 | pinMode(LED_BUILTIN, OUTPUT); 5 | } 6 | 7 | void loop() { 8 | #ifdef INVERSED 9 | digitalWrite(LED_BUILTIN, HIGH); 10 | delay(100); 11 | digitalWrite(LED_BUILTIN, LOW); 12 | delay(150); 13 | digitalWrite(LED_BUILTIN, HIGH); 14 | delay(30); 15 | digitalWrite(LED_BUILTIN, LOW); 16 | delay(1000); 17 | #else 18 | digitalWrite(LED_BUILTIN, LOW); 19 | delay(100); 20 | digitalWrite(LED_BUILTIN, HIGH); 21 | delay(150); 22 | digitalWrite(LED_BUILTIN, LOW); 23 | delay(30); 24 | digitalWrite(LED_BUILTIN, HIGH); 25 | delay(1000); 26 | #endif 27 | } 28 | -------------------------------------------------------------------------------- /sketches/i2c_scanner/i2c_scanner.ino: -------------------------------------------------------------------------------- 1 | // -------------------------------------- 2 | // i2c_scanner 3 | // 4 | // Version 1 5 | // This program (or code that looks like it) 6 | // can be found in many places. 7 | // For example on the Arduino.cc forum. 8 | // The original author is not know. 9 | // Version 2, Juni 2012, Using Arduino 1.0.1 10 | // Adapted to be as simple as possible by Arduino.cc user Krodal 11 | // Version 3, Feb 26 2013 12 | // V3 by louarnold 13 | // Version 4, March 3, 2013, Using Arduino 1.0.3 14 | // by Arduino.cc user Krodal. 15 | // Changes by louarnold removed. 16 | // Scanning addresses changed from 0...127 to 1...119, 17 | // according to the i2c scanner by Nick Gammon 18 | // http://www.gammon.com.au/forum/?id=10896 19 | // Version 5, March 28, 2013 20 | // As version 4, but address scans now to 127. 21 | // A sensor seems to use address 120. 22 | // Version 6, November 27, 2015. 23 | // Added waiting for the Leonardo serial communication. 24 | // 25 | // 26 | // This sketch tests the standard 7-bit addresses 27 | // Devices with higher bit address might not be seen properly. 28 | // 29 | 30 | #include 31 | 32 | 33 | void setup() 34 | { 35 | Wire.begin(); 36 | 37 | Serial.begin(9600); 38 | while (!Serial); // Leonardo: wait for serial monitor 39 | Serial.println("\nI2C Scanner"); 40 | } 41 | 42 | 43 | void loop() 44 | { 45 | byte error, address; 46 | int nDevices; 47 | 48 | Serial.println("Scanning..."); 49 | 50 | nDevices = 0; 51 | for(address = 8; address < 127; address++ ) 52 | { 53 | // The i2c_scanner uses the return value of 54 | // the Write.endTransmisstion to see if 55 | // a device did acknowledge to the address. 56 | Wire.beginTransmission(address); 57 | error = Wire.endTransmission(); 58 | 59 | if (error == 0) 60 | { 61 | Serial.print("I2C device found at address 0x"); 62 | if (address<16) 63 | Serial.print("0"); 64 | Serial.print(address,HEX); 65 | Serial.println(" !"); 66 | 67 | nDevices++; 68 | } 69 | else if (error==4) 70 | { 71 | Serial.print("Unknow error at address 0x"); 72 | if (address<16) 73 | Serial.print("0"); 74 | Serial.println(address,HEX); 75 | } 76 | } 77 | if (nDevices == 0) 78 | Serial.println("No I2C devices found\n"); 79 | else 80 | Serial.println("done\n"); 81 | 82 | delay(5000); // wait 5 seconds for next scan 83 | } 84 | -------------------------------------------------------------------------------- /sketches/motor_l293d_1/motor_l293d_1.ino: -------------------------------------------------------------------------------- 1 | const int in1 = 4; 2 | const int in2 = 5; 3 | const int en1 = 3; 4 | 5 | void setup() { 6 | pinMode(in1, OUTPUT); 7 | pinMode(in2, OUTPUT); 8 | pinMode(en1, OUTPUT); 9 | } 10 | 11 | void loop() { 12 | digitalWrite(in1, HIGH); 13 | digitalWrite(in2, LOW); 14 | 15 | for(int i=0; i<256; i++){ 16 | analogWrite(en1, i); 17 | delay(4); 18 | } 19 | for(int i=255; i>=0; i--){ 20 | analogWrite(en1, i); 21 | delay(4); 22 | } 23 | 24 | digitalWrite(in1, LOW); 25 | digitalWrite(in2, HIGH); 26 | 27 | for(int i=0; i<256; i++){ 28 | analogWrite(en1, i); 29 | delay(4); 30 | } 31 | for(int i=255; i>=0; i--){ 32 | analogWrite(en1, i); 33 | delay(4); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sketches/photodiode_lesson/photodiode_lesson.ino: -------------------------------------------------------------------------------- 1 | byte photoPin = A0; 2 | byte anPins[5] = {A1,A2,A3,A4,A5}; 3 | 4 | void setup() { 5 | Serial.begin(9600); 6 | pinMode( photoPin, INPUT ); 7 | for(byte i=0; i<5; i++){ 8 | pinMode( anPins[i], OUTPUT ); 9 | digitalWrite( anPins[i], LOW ); 10 | } 11 | } 12 | 13 | void loop() { 14 | int v = analogRead(photoPin); 15 | Serial.println(v); 16 | delay(100); 17 | } 18 | -------------------------------------------------------------------------------- /sketches/ppm_pwm/ppm_pwm.ino: -------------------------------------------------------------------------------- 1 | volatile uint8_t prev; // remembers state of input bits from previous interrupt 2 | volatile uint32_t risingEdge[6]; // time of last rising edge for each channel 3 | volatile uint32_t uSec[6]; // the latest measured pulse width for each channel 4 | 5 | ISR(PCINT2_vect) { // one or more of pins 2~7 have changed state 6 | uint32_t now = micros(); 7 | uint8_t curr = PIND; // current state of the 6 input bits 8 | uint8_t changed = curr ^ prev; 9 | int channel = 0; 10 | for (uint8_t mask = 0x04; mask; mask <<= 1) { 11 | if (changed & mask) { // this pin has changed state 12 | if (curr & mask) { // +ve edge so remember time 13 | risingEdge[channel] = now; 14 | } 15 | else { // -ve edge so store pulse width 16 | uSec[channel] = now - risingEdge[channel]; 17 | } 18 | } 19 | channel++; 20 | } 21 | prev = curr; 22 | } 23 | 24 | void setup() { 25 | Serial.begin(9600); 26 | 27 | for (int pin = 2; pin <= 7; pin++) { // enable pins 2 to 7 as our 6 input bits 28 | pinMode(pin, INPUT); 29 | } 30 | 31 | PCMSK2 |= 0xFC; // set the mask to allow those 6 pins to generate interrupts 32 | PCICR |= 0x04; // enable interupt for port D 33 | } 34 | 35 | void loop() { 36 | Serial.flush(); 37 | for (int channel = 0; channel < 6; channel++) { 38 | Serial.print(uSec[channel]); 39 | Serial.print("\t"); 40 | } 41 | Serial.println(); 42 | } 43 | -------------------------------------------------------------------------------- /sketches/rgb_control/rgb_control.ino: -------------------------------------------------------------------------------- 1 | int clr[3] = {9,10,11}; 2 | int to = 3; 3 | 4 | void setup() { 5 | for(int i=0; i<3; i++) 6 | pinMode(clr[i], OUTPUT); 7 | 8 | setColor(0,255,0); 9 | delay(1000); 10 | setColor(0,0,255); 11 | delay(1000); 12 | setColor(255,0,0); 13 | delay(1000); 14 | } 15 | 16 | void loop() { 17 | for(int i=0;i<256;i++){ 18 | setColor(255,i,0); 19 | delay(to); 20 | } 21 | for(int i=255;i>=0;i--){ 22 | setColor(i,255,0); 23 | delay(to); 24 | } 25 | for(int i=0;i<256;i++){ 26 | setColor(0,255,i); 27 | delay(to); 28 | } 29 | for(int i=255;i>=0;i--){ 30 | setColor(0,i,255); 31 | delay(to); 32 | } 33 | for(int i=0;i<256;i++){ 34 | setColor(i,0,255); 35 | delay(to); 36 | } 37 | for(int i=255;i>=0;i--){ 38 | setColor(255,0,i); 39 | delay(to); 40 | } 41 | 42 | } 43 | 44 | void setColor(byte r, byte g, byte b ){ 45 | analogWrite(clr[0], r); 46 | analogWrite(clr[1], g); 47 | analogWrite(clr[2], b); 48 | } 49 | 50 | 51 | -------------------------------------------------------------------------------- /sketches/rgb_ring/rgb_ring.ino: -------------------------------------------------------------------------------- 1 | // NeoPixel Ring simple sketch (c) 2013 Shae Erisson 2 | // released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library 3 | #include // I2C library, required for MLX90614 4 | #include // SparkFunMLX90614 Arduino library 5 | 6 | #include 7 | #ifdef __AVR__ 8 | #include 9 | #endif 10 | 11 | #define PIN 12 12 | #define NUMPIXELS 16 13 | 14 | // When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals. 15 | // Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest 16 | // example for more information on possible values. 17 | Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); 18 | IRTherm therm; 19 | 20 | int delayval = 3; // delay for half a second 21 | 22 | const int colormap[] ={1, 3, 74, 0, 3, 75, 0, 3, 76, 0, 3, 77, 0, 3, 82, 0, 7, 88, 0, 14, 94, 0, 22, 100, 0, 28, 106, 0, 35, 112, 0, 40, 119, 0, 45, 128, 0, 50, 134, 0, 52, 137, 0, 54, 142, 0, 56, 145, 0, 61, 154, 0, 65, 159, 0, 68, 164, 0, 71, 170, 0, 75, 179, 0, 78, 184, 0, 80, 188, 0, 84, 194, 0, 88, 200, 0, 92, 205, 0, 94, 208, 0, 96, 210, 0, 99, 214, 0, 103, 218, 0, 105, 220, 0, 109, 223, 0, 113, 223, 0, 117, 221, 1, 120, 219, 2, 124, 216, 3, 129, 212, 4, 132, 205, 4, 134, 197, 6, 138, 185, 8, 142, 172, 10, 144, 162, 12, 146, 153, 15, 149, 140, 22, 153, 120, 28, 156, 109, 40, 160, 94, 51, 164, 79, 67, 171, 60, 78, 175, 48, 89, 179, 39, 98, 183, 31, 109, 187, 23, 118, 189, 19, 128, 193, 14, 138, 196, 10, 146, 198, 6, 155, 201, 4, 164, 204, 2, 173, 206, 1, 178, 207, 1, 190, 210, 0, 196, 212, 0, 202, 213, 1, 212, 215, 3, 218, 214, 3, 222, 213, 4, 225, 212, 5, 229, 211, 5, 232, 211, 6, 234, 210, 6, 236, 209, 7, 239, 206, 8, 242, 203, 9, 244, 201, 10, 245, 199, 11, 247, 197, 12, 249, 191, 14, 251, 187, 15, 252, 183, 17, 253, 174, 19, 254, 168, 20, 254, 164, 21, 255, 161, 22, 255, 157, 23, 255, 149, 25, 255, 139, 28, 255, 131, 31, 255, 118, 34, 255, 104, 37, 255, 99, 39, 255, 88, 42, 254, 77, 45, 254, 62, 49, 253, 53, 52, 252, 45, 55, 251, 33, 59, 251, 31, 60, 251, 29, 61, 250, 27, 63, 249, 26, 66, 248, 25, 70, 247, 24, 75, 247, 25, 79, 247, 32, 83, 247, 38, 86, 247, 46, 90, 248, 55, 94, 248, 64, 98, 249, 81, 104, 250, 93, 108, 250, 98, 110, 251, 101, 112, 251, 109, 117, 252, 121, 123, 253, 130, 128, 254, 139, 133, 254, 151, 140, 255, 163, 146, 255, 173, 152, 255, 178, 155, 255, 191, 165, 255, 199, 172, 255, 207, 179, 255, 216, 185, 255, 220, 196, 255, 225, 202, 255, 230, 206}; 23 | 24 | void setup() { 25 | therm.begin(); // Initialize thermal IR sensor 26 | therm.setUnit(TEMP_C); // Set the library's units to Farenheit 27 | Serial.begin(9600); 28 | pixels.begin(); // This initializes the NeoPixel library. 29 | } 30 | 31 | void loop() { 32 | int t; 33 | if (therm.read()){ 34 | t = int(((therm.object()-0)/60.0)*127); 35 | for(int i=0; i 0 ){ 110 | incomingByte = Serial.read(); 111 | if(state==PAUSED) 112 | return; 113 | if( incomingByte>='0' && incomingByte<='9' ){ 114 | cspeed = 100+(incomingByte-48)*15; 115 | //setSpeed(cspeed); 116 | return; 117 | } 118 | movement(incomingByte); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /sketches/weather_ctrl/weather_ctrl.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * SD card attached to SPI bus as follows: 3 | ** MOSI - pin 11 4 | ** MISO - pin 12 5 | ** CLK - pin 13 6 | ** CS - pin 10 7 | */ 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "DHT.h" 14 | 15 | 16 | DHT dht(2, DHT22); 17 | BMP085 bmp = BMP085(); 18 | 19 | const int temp_to = 1000; 20 | const int save_to = 500; 21 | long temp_t = 0; 22 | long save_t = 0; 23 | 24 | long tt = 0; 25 | 26 | File logFile; 27 | 28 | int buzzPin = 4; 29 | int tempPin = A3; 30 | int solPin = A2; 31 | 32 | int val; 33 | double d_temp = 0.0; 34 | long d_alt = 0; 35 | double d_hum = 0.0; 36 | int d_sol = 0; 37 | double baseline = 0.0; 38 | long file_pos = 0; 39 | 40 | void beep( int cnt, int dl ){ 41 | for( int i=0; i temp_t + temp_to ){ 116 | temp_t = tt; 117 | d_temp = getTemp(); 118 | d_alt = getAlt(); 119 | d_hum = getHum(); 120 | d_sol = getSol(); 121 | } 122 | 123 | tt = millis(); 124 | if( tt > save_t + save_to ){ 125 | save_t = tt; 126 | saveData( d_temp, d_alt, d_hum ); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /sketches/weather_sirena/weather_sirena.ino: -------------------------------------------------------------------------------- 1 | unsigned long int LED_TIMEOUT_MS = 2000; 2 | unsigned long int SIR_TIMEOUT_MS = 10000; 3 | 4 | unsigned long int time_led = 0; 5 | unsigned long int time_sir = 0; 6 | 7 | int led_pin = 7; 8 | int sir_pin = 6; 9 | 10 | void setup() { 11 | pinMode(led_pin, OUTPUT); 12 | pinMode(sir_pin, OUTPUT); 13 | 14 | //7200 15 | digitalWrite(sir_pin, LOW); 16 | digitalWrite(led_pin, LOW); 17 | for( long i=0; i<7200; i++ ){ 18 | delay(1000); 19 | } 20 | } 21 | 22 | void loop() { 23 | if( millis()>(time_led+LED_TIMEOUT_MS) ){ 24 | time_led = millis(); 25 | digitalWrite(led_pin, HIGH); 26 | delay(500); 27 | digitalWrite(led_pin, LOW); 28 | delay(500); 29 | } 30 | if( millis()>time_sir+SIR_TIMEOUT_MS ){ 31 | time_sir = millis(); 32 | digitalWrite(sir_pin, HIGH); 33 | delay(1000); 34 | digitalWrite(sir_pin, LOW); 35 | delay(500); 36 | } 37 | } 38 | --------------------------------------------------------------------------------