0 / 0 / 0
Регистрация: 14.09.2023
Сообщений: 2
1

Ошибка при компиляции скетча Arduino

14.09.2023, 19:54. Показов 765. Ответов 3
Метки нет (Все метки)

Студворк — интернет-сервис помощи студентам
Добрый день, умные люди помогите пожалуйста разобраться в чем ошибка, в програмировании совсем новичёк, код не мой
ПРОШУ ПОМОЩИ!!!

КОД:
C++
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
// Developed in Arduino IDE 1.8.13 (Windows)
 
#include <FastLED.h> // FastLED version 3.3.3 [url]https://github.com/FastLED/FastLED[/url]
#include "MIDIUSB.h" // MIDIUSB version 1.0.4 [url]https://www.arduino.cc/en/Reference/MIDIUSB[/url]
 
#define BUTTON_PIN1 3
#define BUTTON_PIN2 2
#define LED_ACT_PIN 4
#define LED_PIN     5
#define NUM_LEDS    144
#define LED_TYPE    WS2812B
#define COLOR_ORDER GRB
#define AMPERAGE    1500     // Power supply amperage in mA
 
#define NOTE_OFFSET   29     // Offset of first note from left (depends on Piano)
#define LEDS_PER_NOTE 2      // How many LED are on per key
#define LED_INT_STEPS 8      // LED Intensity button steps
 
#define DEBUG
 
CRGB leds[NUM_LEDS];
byte color = 0xFFFFFF;
int ledProgram = 1;
int ledIntensity = 2;  // default LED brightness
int ledBrightness = ceil(255 / LED_INT_STEPS * ledIntensity); // default LED brightness
int buttonState1;
int buttonState2;
int lastButtonState1 = LOW;
int lastButtonState2 = LOW;
unsigned long lastDebounceTime1 = 0;
unsigned long lastDebounceTime2 = 0;
unsigned long debounceDelay = 50;
 
//------------------------------------------- FUNCTIONS ----------------------------------------------//
 
const char* pitch_name(byte pitch) {
  static const char* names[] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"};
  return names[pitch % 12];
}
 
int pitch_octave(byte pitch) {
  return (pitch / 12) - 1;
}
 
void SetNote(byte pitch, CRGB color) {
  int b = 0;
  for (int a = 0; a < LEDS_PER_NOTE; a++) {
    //if (int(pitch) > 66){b=1;}else{b=0;} // led stripe solder joints compensation
    leds[(((pitch - NOTE_OFFSET)*LEDS_PER_NOTE)+ a - b)]= color;
  }
}
 
void SetNote2(byte pitch, int hue) {
  int b = 0;
  for (int a = 0; a < LEDS_PER_NOTE; a++) {
    //if (int(pitch) > 66){b=1;}else{b=0;} // led stripe solder joints compensation
    leds[(((pitch - NOTE_OFFSET)*LEDS_PER_NOTE)+a - b)].setHSV(hue, 255, 255);
  }
}
 
void noteOn(byte channel, byte pitch, byte velocity) {
  if (velocity > 0) {
    switch (channel) {
 
      // Left Hand
    case 144: // Default Channel is 144
    case 155:
    case 145 ... 149:
      if (ledProgram == 1){
        SetNote(pitch,0x0000FF);
      }else if (ledProgram == 2){
        SetNote(pitch,0x00FF00);
      }else if (ledProgram == 3){
        SetNote2(pitch,pitch*velocity);
      }else if (ledProgram == 4){
        SetNote2(pitch,velocity*2);
      }else if (ledProgram == 5){
        SetNote(pitch,0xFFFFFF);
      }else if (ledProgram == 6){
        SetNote2(pitch,ceil((pitch-NOTE_OFFSET) * (255/(NUM_LEDS/LEDS_PER_NOTE))));
      }else{
      }
      break;
      
      // Right Hand
    case 156:
    case 150 ... 154:
      SetNote(pitch,0x00FF00);
      break;
      
    default:
      SetNote(pitch,0xFFFFFF);
      break;
    }
 
    if (DEBUG == true){     Serial.println("Note ON   - Channel:" + String(channel) + " Pitch:" + String(pitch) + " Note:" + pitch_name(pitch) + String(pitch_octave(pitch)) + " Velocity:" + String(velocity)); }
  }else{   
    SetNote(pitch,0x000000); // black
    if (DEBUG == true){     Serial.println("Note OFF2 - Channel:" + String(channel) + " Pitch:" + String(pitch) + " Note:" + pitch_name(pitch) + String(pitch_octave(pitch)) + " Velocity:" + String(velocity)); }
  }
  FastLED.show();
}
 
void noteOff(byte channel, byte pitch, byte velocity) {
  if (ledProgram == 5){
    fill_rainbow( leds, NUM_LEDS, 0, 5);
  }else{
    SetNote(pitch,0x000000); // black
  }
 
  #ifdef DEBUG
  Serial.print("Note OFF  - Channel:");
  Serial.print(String(channel));
  Serial.print(" Pitch:");
  Serial.print(String(pitch));
  Serial.print(" Note:");
  Serial.print(pitch_name(pitch) + String(pitch_octave(pitch)));
  Serial.print(" Velocity:");
  Serial.println(String(velocity));
  #endif
  FastLED.show();
}
 
void controlChange(byte channel, byte control, byte value) {
  #ifdef DEBUG
  Serial.print("Control  - Channel:");
  Serial.print(String(channel));
  Serial.print(" Control:");
  Serial.print(String(control));
  Serial.print(" Value:");
  Serial.println(String(value));
  #endif
}
 
//-------------------------------------------- SETUP ----------------------------------------------//
 
void setup() {
  #ifdef DEBUG
  Serial.begin(115200);
  #endif
  delay( 3000 ); // power-up safety delay
  FastLED.setMaxPowerInVoltsAndMilliamps(5, AMPERAGE);
  pinMode(BUTTON_PIN1, INPUT_PULLUP);
  pinMode(BUTTON_PIN2, INPUT_PULLUP);
  pinMode(LED_ACT_PIN, OUTPUT);
  FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  FastLED.setBrightness(ledBrightness);
  fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
  SetNote(NOTE_OFFSET+ledProgram-1,0xFF0000);
  FastLED.show();
  #ifdef DEBUG
  Serial.println("MIDI2Neopixel is ready!");
  #endif
}
 
//--------------------------------------------- LOOP ----------------------------------------------//
void loop() {
  ////////////////////////////////////////////// Button 1 /////////////////////////////////////////////
 
  int reading1 = digitalRead(BUTTON_PIN1);
 
  if (reading1 != lastButtonState1) {
    lastDebounceTime1 = millis();
  }
 
  if ((millis() - lastDebounceTime1) > debounceDelay) {
    if (reading1 != buttonState1) {
      buttonState1 = reading1;
 
      // only toggle the LED if the new button state is HIGH
      if (buttonState1 == LOW) {
        ledProgram++;
        if (ledProgram>6){
          ledProgram = 1;
        }
        if (DEBUG == true){     Serial.println("Button 1 pressed! Program is " + String(ledProgram)); }
        // Set LED indication for program
        fill_solid( leds, NUM_LEDS, CRGB(0,0,0));
        SetNote(NOTE_OFFSET+ledProgram-1,0xFF0000);
        FastLED.show();
      }
    }
  }
 
  ////////////////////////////////////////////// Button 2 /////////////////////////////////////////////
 
  int reading2 = digitalRead(BUTTON_PIN2);
 
  if (reading2 != lastButtonState2) {
    lastDebounceTime2 = millis();
  }
 
  if ((millis() - lastDebounceTime2) > debounceDelay) {
    if (reading2 != buttonState2) {
      buttonState2 = reading2;
 
      // only toggle the LED if the new button state is HIGH
      if (buttonState2 == LOW) {
        ledIntensity++;
        SetNote(NOTE_OFFSET+ledIntensity-2,0x000000);
        if (ledIntensity>LED_INT_STEPS){
          ledIntensity = 1;
        }
        // Map ledIntensity to ledBrightness
        ledBrightness = map(ledIntensity, 1, LED_INT_STEPS, 3, 255);
        FastLED.setBrightness(ledBrightness);
        #ifdef DEBUG
        Serial.print("Button 2 pressed! Intensity is ");
        Serial.print(String(ledIntensity));
        Serial.print(" and brightness to ");
        Serial.print(String(ledBrightness));
        #endif
        // Set LED indication for program
        SetNote(NOTE_OFFSET+ledIntensity-1,0x00FF00);
        FastLED.show();
      }
    }
  }
 
  ////////////////////////////////////////// MIDI Read routine ////////////////////////////////////////
  midiEventPacket_t rx = MidiUSB.read();
  if (rx.header) {digitalWrite(LED_ACT_PIN, HIGH);}
  switch (rx.header) {
  case 0:
    break; //No pending events
    
  case 0x9:
    noteOn(rx.byte1,rx.byte2,rx.byte3);
    break;
    
  case 0x8:
    noteOff(rx.byte1,rx.byte2,rx.byte3);
    break;
    
  case 0xB:
    controlChange(rx.byte1 & 0xF,rx.byte2,rx.byte3);
    break;
    
  default:
    #ifdef DEBUG
    Serial.print("Unhandled MIDI message: ");
    Serial.print(rx.header, HEX);
    Serial.print("-");
    Serial.print(rx.byte1, HEX);
    Serial.print("-");
    Serial.print(rx.byte2, HEX);
    Serial.print("-");
    Serial.println(rx.byte3, HEX);
    #endif
    break;
  }
 
 
  if (rx.header) {digitalWrite(LED_ACT_PIN, LOW);}
  lastButtonState1 = reading1;
  lastButtonState2 = reading2;
}
//------------------------------------------ END OF LOOP -------------------------------------------//
ОШИБКА:

C:\Users\Ildar\Desktop\MIDI2Neopixel-main\Software\MIDI2Neopixel\MIDI2Neopixel.ino:22:14: warning: large integer implicitly truncated to unsigned type [-Woverflow]
byte color = 0xFFFFFF;
^~~~~~~~
C:\Users\Ildar\Desktop\MIDI2Neopixel-main\Software\MIDI2Neopixel\MIDI2Neopixel.ino: In function 'void noteOn(byte, byte, byte)':
MIDI2Neopixel:96:15: error: expected primary-expression before '==' token
if (DEBUG == true){ Serial.println("Note ON - Channel:" + String(channel) + " Pitch:" + String(pitch) + " Note:" + pitch_name(pitch) + String(pitch_octave(pitch)) + " Velocity:" + String(velocity)); }
^~
MIDI2Neopixel:99:15: error: expected primary-expression before '==' token
if (DEBUG == true){ Serial.println("Note OFF2 - Channel:" + String(channel) + " Pitch:" + String(pitch) + " Note:" + pitch_name(pitch) + String(pitch_octave(pitch)) + " Velocity:" + String(velocity)); }
^~
C:\Users\Ildar\Desktop\MIDI2Neopixel-main\Software\MIDI2Neopixel\MIDI2Neopixel.ino: In function 'void loop()':
MIDI2Neopixel:176:19: error: expected primary-expression before '==' token
if (DEBUG == true){ Serial.println("Button 1 pressed! Program is " + String(ledProgram)); }
^~
exit status 1
expected primary-expression before '==' token
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
14.09.2023, 19:54
Ответы с готовыми решениями:

Ошибка при компиляции скетча (FMTX)
Искал в интернете способ решения данной проблемы, но не смог найти... Сперва была ошибка &quot;note:...

Ошибка компиляции скетча
Код не хочет компилироваться. Использую ядро от GyverCore. Предопределяя вопрос, на дефолтном ядре...

Arduino. Ошибка при компиляции
Помогите исправить ошибку в коде, программа (Andruino) void setup() { pinMode(5, INPUT); //dh...

Пиксельная подсветка на WS2801 ошибка компиляции скетча
Добрый день. Очень нужна помощь делаю подобие амбилайт на ардуино нано по гайду...

3
515 / 407 / 188
Регистрация: 08.04.2013
Сообщений: 1,736
14.09.2023, 21:41 2
для начала 19 строка DEBUG не определен!
C++
1
 #define DEBUG  true //или false
1
32 / 27 / 8
Регистрация: 17.02.2014
Сообщений: 116
15.09.2023, 12:43 3
Цитата Сообщение от Good Company Посмотреть сообщение
byte color = 0xFFFFFF;
byte обрежет значение до 0xFF
1
0 / 0 / 0
Регистрация: 14.09.2023
Сообщений: 2
15.09.2023, 18:54  [ТС] 4
Спасибо огромное!!!
0
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
15.09.2023, 18:54
Помогаю со студенческими работами здесь

Выполнение скетча на Arduino Nano
Есть Arduino, которая подключается к ПК, получает на serial-порту 2 числа и начинает свою работу....

Заливка скетча в Arduino Pro-Mini в Debian
Доброго времени! Есть Arduino mini pro ATmega168 5V и Debian 7 (и в том и в другом глубокий нуб)....

Ошибка при работе скетча
Arduino Nano. Выделение цифр числа в цикле loop происходит правильно, а в процедуре и дальнейшей...

Некорректная работа скетча Arduino от внешнего источника питания
Всем здравствуйте! Я с ардуино начал знакомство недавно, опыта не имеется, новичок в общем...

Произошла ошибка при загрузке скетча
Произошла ошибка при загрузке скетча

Ошибка при компиляции скетча на запись сканкодов клавиш на SD карту
Есть такой код, при компиляции выдает ошибку: keylogger.ino: In function 'void setup()':...

Проблема с заливкой скетча arduino.
Всем привет. Вчера пришла новенькая arduino uno. Установил arduino ide. После подключения платы к...


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
4
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2023, CyberForum.ru