2020#define SOUND_TOUCH_FREQ_HZ 800 // частота звукового сигнала после обнаружения касания
2121#define SOUND_VIBR_FREQ_HZ 2500 // частота звукового сигнала после обнаружения вибрации
2222
23- #include < TM74HC595Display.h>
2423#include < SPI.h>
2524#include < Ethernet.h>
2625
27- // типы мелодий которые могут играть
28- enum MELODY_TYPE {
29- INIT_MELODY, // начальная мелодия при включении
30- GAIN_10_MELODY, // каждые 10 очков
31- GAIN_100_MELODY // каждые 100 очков
32- };
26+ #include < TM74HC595Display.h>
27+ 28+ #include " play_melody.h"
3329
3430TM74HC595Display disp (SCLK_PIN, RCLK_PIN, DIO_PIN); // дисплей
3531EthernetClient client; // клиент Ethernet
@@ -55,10 +51,10 @@ void setup() {
5551 pinMode (BLUE_LIGHT_PIN, OUTPUT);
5652 pinMode (SOUND_PIN, OUTPUT);
5753
58- disp.clear (); // очистить дисплей
59- play_melody (INIT_MELODY); // играть начальную мелодию
60- digitalWrite (RED_LIGHT_PIN, HIGH); // включить красный светодиод
61- disp.digit4 (0 ); // вывести 0 на дисплей
54+ disp.clear (); // очистить дисплей
55+ play_melody (INIT_MELODY, SOUND_PIN); // играть начальную мелодию
56+ digitalWrite (RED_LIGHT_PIN, HIGH); // включить красный светодиод
57+ disp.digit4 (0 ); // вывести 0 на дисплей
6258}
6359
6460void loop () {
@@ -106,10 +102,10 @@ void loop() {
106102
107103 // если число кратно 10 или 100 проиграть мелодию
108104 if (num_detected % 10 == 0 && num_detected != 0 && num_detected % 100 != 0 ) {
109- play_melody (GAIN_10_MELODY);
105+ play_melody (GAIN_10_MELODY, SOUND_PIN );
110106 }
111107 else if (num_detected % 100 == 0 && num_detected != 0 ) {
112- play_melody (GAIN_100_MELODY);
108+ play_melody (GAIN_100_MELODY, SOUND_PIN );
113109 }
114110 }
115111}
@@ -228,35 +224,6 @@ void check_display() {
228224 }
229225}
230226
231- void play_melody (MELODY_TYPE melody_type) {
232- #include " melody.h"
233- 234- switch (melody_type) {
235- case INIT_MELODY:
236- play_one_melody (init_melody, init_note_durations, init_melody_duration);
237- break ;
238- 239- case GAIN_10_MELODY:
240- play_one_melody (gain_10_melody, gain_10_note_durations, gain_10_melody_duration);
241- break ;
242- 243- case GAIN_100_MELODY:
244- play_one_melody (gain_100_melody, gain_100_note_durations, gain_100_melody_duration);
245- break ;
246- }
247- }
248- 249- void play_one_melody (const uint16_t melody[], const uint8_t note_durations[], const uint8_t num_notes) {
250- for (uint8_t current_note = 0 ; current_note < num_notes; current_note++) {
251- uint16_t note_duration = 1000 / note_durations[current_note];
252- uint16_t pause_between_notes = note_duration * 1.20 ;
253- 254- tone (SOUND_PIN, melody[current_note], note_duration);
255- delay (pause_between_notes);
256- noTone (SOUND_PIN);
257- }
258- }
259- 260227// посчитать кол-во цифр в числе
261228// необходимо для подсчёта Content-Length в запросе
262229uint8_t count_digits_uint (uint16_t val) {
0 commit comments