Hi Guys
I am a newbie of Arduino, I want to use Visual Studio with Visual Micro to programing. I have installed the 3 soft:
1, Visual Studio 2017
2, Visual Micro(latest version)
3, Arduino IDE(latest version)
I have try to compile of Arduino example program, it is OK
but there are error with my program
here is the error message
I'd use #include <Wire.h>
YMMV.
Please post the text of error messages, not an image.
Thank you for you reply, here is the error message
Compiling 'Analog_VU_Meter' for 'Arduino/Genuino Uno'
Error linking for board Arduino/Genuino Uno
ccKkPI8e.ltrans0.ltrans.o*: In function setup
Build failed for project 'Analog_VU_Meter'
Analog_VU_Meter.ino:40: undefined reference to Wire
Analog_VU_Meter.ino:40: undefined reference to Wire
Analog_VU_Meter.ino:40: undefined reference to TwoWire begin()
collect2.exe*: error: ld returned 1 exit status
here is the code of my program
/*
Analog VU mete
_____________________
Wiring goes as follows:
- USB red wire (5v) to VCC
- USB black wire to GND
- Audio left channel to 10K resistor to Analog 1
- Audio right channel to 10K resistor to Analog 2
- Audio ground to GND
- Potentiometer to Analog 0 (follow arduino tutorial: http://arduino.cc/en/uploads/Tutorial/graph-circuit3.png )
- Left Analog Meter to Digital 5 (PWM)
- Right Analog Meter to Digital 6 (PWM)
_______________________
Note:
Because all meters are slightly different, the PWM values
need to be adjusted based on your design. Feel free to use
my code, but you will have to change some values because
it is set to work specifically with my meters.
*/
#include"Wire.h"
byte zero = 0x00; //workaround for issue #527
int leftMeter = 5; // left meter (hours) is attached to pin 5 (PWM)
int rightMeter = 6; // right meter (min) is attached to pin 6 (PWM)
int leftChannel = 0; // left channel of audio (analog 1)
int rightChannel = 0; // right channel of audio (analog 2)
int sensitivity = 0; // 10k pot sensitivity control (analog 0)
int rightLevel = 0; // position of the right meter
int leftLevel = 0; // position of the left meter
// rtc - SDA to A4 - SCL to A5
void setup() {
Wire.begin();
//Serial.begin(9600); //Un-comment to view time in serial monitor
pinMode(leftMeter, OUTPUT); // Initialize Outputs
pinMode(rightMeter, OUTPUT);
digitalWrite(leftMeter, HIGH); // Test meters on startup
digitalWrite(rightMeter, HIGH);
digitalWrite(13, HIGH);
delay(1000);
digitalWrite(leftMeter, LOW);
digitalWrite(rightMeter, LOW);
digitalWrite(13, LOW);
delay(1000);
}
void loop() {
sensitivity = (analogRead(A0) / 3 + 1); // potentiometer sensitivity control
analogWrite(leftMeter, leftLevel); // adjust left meter level
analogWrite(rightMeter, rightLevel); // adjust right meter level
leftChannel = analogRead(A1); // read left channel of audio
rightChannel = analogRead(A2); // read right channel of audio
// Below is the code to set meter levels based on sound levels:
// If you change the values, remember to make sure that the Left and Right channels are matching.
// leftLevel and rightLevel can be set from 0 to 255 (PWM)
// (clock code starts at line 204)
if (leftChannel >= sensitivity && leftLevel < 20) {
leftLevel = 20;
}
if (rightChannel >= sensitivity && rightLevel < 20) {
rightLevel = 20;
}
if (leftChannel >= sensitivity + 5 && leftLevel < 41) {
leftLevel = 41;
}
if (rightChannel >= sensitivity + 5 && rightLevel < 41) {
rightLevel = 41;
}
if (leftChannel >= sensitivity + 10 && leftLevel < 62) {
leftLevel = 62;
}
if (rightChannel >= sensitivity + 10 && rightLevel < 62) {
rightLevel = 62;
}
if (leftChannel >= sensitivity + 15 && leftLevel < 83) {
leftLevel = 83;
}
if (rightChannel >= sensitivity + 15 && rightLevel < 83) {
rightLevel = 83;
}
if (leftChannel >= sensitivity + 20 && leftLevel < 104) {
leftLevel = 104;
}
if (rightChannel >= sensitivity + 20 && rightLevel < 104) {
rightLevel = 104;
}
if (leftChannel >= sensitivity + 25 && leftLevel < 125) {
leftLevel = 125;
}
if (rightChannel >= sensitivity + 25 && rightLevel < 125) {
rightLevel = 125;
}
if (leftChannel >= sensitivity + 30 && leftLevel < 146) {
leftLevel = 146;
}
if (rightChannel >= sensitivity + 30 && rightLevel < 146) {
rightLevel = 146;
}
if (leftChannel >= sensitivity + 35 && leftLevel < 167) {
leftLevel = 167;
}
if (rightChannel >= sensitivity + 35 && rightLevel < 167) {
rightLevel = 167;
}
if (leftChannel >= sensitivity + 37 && leftLevel < 188) {
leftLevel = 188;
}
if (rightChannel >= sensitivity + 37 && rightLevel < 188) {
rightLevel = 188;
}
if (leftChannel >= sensitivity + 40 && leftLevel < 209) {
leftLevel = 209;
}
if (rightChannel >= sensitivity + 40 && rightLevel < 209) {
rightLevel = 209;
}
if (leftChannel >= sensitivity + 42 && leftLevel < 230) {
leftLevel = 230;
}
if (rightChannel >= sensitivity + 42 && rightLevel < 230) {
rightLevel = 230;
}
if (leftChannel >= sensitivity + 45 && leftLevel < 255) {
leftLevel = 255;
}
if (rightChannel >= sensitivity + 45 && rightLevel < 255) {
rightLevel = 255;
}
// Fade the meters out to 0
if (leftChannel < sensitivity && leftLevel > 0) {
leftLevel = --leftLevel; // left meter
delayMicroseconds(1000); // can be increased and decreased to adjust smoothness
} // (how long it takes to get back to 0)
if (rightChannel < sensitivity && rightLevel > 0) {
rightLevel = --rightLevel; // right meter
delayMicroseconds(1000); // can be increased and decreased to adjust smoothness
} // (how long it takes to get back to 0)
} //end of loop()
It builds in the Arduino ide. Are you seeing anything telling you that the compiler couldn't find wire.h? Since it's a linker error though, I assume you need to add wire.cpp to your build script (make file)
There were a couple of unrelated warnings:
warning: operation on 'leftLevel' may be undefined [-Wsequence-point]
This:
leftLevel = --leftLevel; // left meter
would be better:
--leftLevel; // left meter
Same thing for rightLevel.
wildbill:
It builds in the Arduino ide. Are you seeing anything telling you that the compiler couldn't find wire.h? Since it's a linker error though, I assume you need to add wire.cpp to your build script (make file)There were a couple of unrelated warnings:
warning: operation on 'leftLevel' may be undefined [-Wsequence-point]This:
leftLevel = --leftLevel; // left meter
would be better:
--leftLevel; // left meter
Same thing for rightLevel.
I have built it in Arduino IDE, it is all fine, without any error.
I suspect then that you don't have warnings turned up to the max in preferences. That abuse of the -- operator is clearly erroneous.