fix the 8 and add a } at the end
Announcement
Collapse
No announcement yet.
Arduino metal detector?
Collapse
X
-
Just scratch that . I used cut and past to copy the Write to commands and forgot to delete the Clear commands on each step so it would never see any progression. I'll correct it and post as attachment. Sorry. http://www.pacdv.com/sounds/fart-sounds/fart-7.mp3
Comment
-
Hope this does the job. Modified the Digital Write to progress in step with Int ss levels keeping LED's ON until end of cycle at which time they are cleared.
You said LED were Jumping. Did you wire LED in sequence ? On the NANO D0 and D1 are Reversed.
I'm a NU BEE at this Arduino thing too so I hope I got this right.
ArduinoNano30Schematic.pdf
RussianPIModifiedCode1.txt
Comment
-
The code can be made a lot more compact.
PHP Code:int s[3] = {0};
int ss[3] = {0};
int sss[3] = {0};
long c[3] = {0};
void setup()
{
DDRB = 0xFF; // port B - all out
DDRD = 0xFF; // port D - all out
for (char i = 0; i <255; i++) // калибровка / calibration
{
PORTB = 0b11111111; // переводим пины порта B в 1, открывая т.о. ключ (turn on)
delayMicroseconds(200); // wait 200 microseconds
PORTB = 0; //
delayMicroseconds(20);
s[0] = analogRead(A0);
s[1] = analogRead(A0);
s[2] = analogRead(A0);
c[i] += s[i];
delay(3);
}
for (char i = 0; i <3; i++) c[i] = (c[i] >> 8) - 5;
}
void loop()
{
PORTB = 0b11111111; // переводим пины порта B в 1, открывая т.о. ключ (turn on)
delayMicroseconds(200); // wait 200 microseconds
PORTB = 0; // закрывааем ключ, прерывая ток в поисковой катушке (turn off - interrupt circut in search coil )
delayMicroseconds(20);
s[0] = analogRead(A0);
s[1] = analogRead(A0);
s[2] = analogRead(A0);
for (char i = 0; i < 3; i++)
{
ss[i] = s[i] - c[i];
if (ss[i] < 0) sss[i] = 1;
ss[i] = ss[i] >> 4;
PORTD = ss[i]; // посылаем на индикатор (send to LEDs)
delay(1);
}
int code = sss[0] + sss[1] + sss[2];
PORTD = (code > 8)? 0xFF : (1 << code) - 1;
delay(1);
sss[0] = 0;
sss[1] = 0;
sss[2] = 0;
}
Comment
-
Thanks for the code, it will verify and upload to the nano, but all that happens with any signal input to A0, is the led that is connected to pin 2 / D0/ RX stays permanently lit and nothing else changes.
Originally posted by Teleno View PostThe code can be made a lot more compact.
PHP Code:int s[3] = {0};
int ss[3] = {0};
int sss[3] = {0};
long c[3] = {0};
void setup()
{
DDRB = 0xFF; // port B - all out
DDRD = 0xFF; // port D - all out
for (char i = 0; i <255; i++) // калибровка / calibration
{
PORTB = 0b11111111; // переводим пины порта B в 1, открывая т.о. ключ (turn on)
delayMicroseconds(200); // wait 200 microseconds
PORTB = 0; //
delayMicroseconds(20);
s[0] = analogRead(A0);
s[1] = analogRead(A0);
s[2] = analogRead(A0);
c[i] += s[i];
delay(3);
}
for (char i = 0; i <3; i++) c[i] = (c[i] >> 8) - 5;
}
void loop()
{
PORTB = 0b11111111; // переводим пины порта B в 1, открывая т.о. ключ (turn on)
delayMicroseconds(200); // wait 200 microseconds
PORTB = 0; // закрывааем ключ, прерывая ток в поисковой катушке (turn off - interrupt circut in search coil )
delayMicroseconds(20);
s[0] = analogRead(A0);
s[1] = analogRead(A0);
s[2] = analogRead(A0);
for (char i = 0; i < 3; i++)
{
ss[i] = s[i] - c[i];
if (ss[i] < 0) sss[i] = 1;
ss[i] = ss[i] >> 4;
PORTD = ss[i]; // посылаем на индикатор (send to LEDs)
delay(1);
}
int code = sss[0] + sss[1] + sss[2];
PORTD = (code > 8)? 0xFF : (1 << code) - 1;
delay(1);
sss[0] = 0;
sss[1] = 0;
sss[2] = 0;
}
Comment
-
Originally posted by kosacid View Postfix the 8 and add a } at the end
Thanks for the information, yes it worked, I took a fresh copy of Homefires code in post #86 (Thanks Homey) and fixed the "8' and added an extra } at the very end of the code and it verify's and uploads to the nano, it does work a little better than the original code you can see some progression in the BRIGHTNESS and flickering of the led's, to a point, but the way the leds are so erratic its very hard to work out what the meaning of the erratic flickering leds are indicating. It was fun trying.
Comment
-
Try adding a few more uS of delay at each delay point. Make a Delay 1 Delay 5..
======
delay(3);
}
c0 = c0 / 255;
c0 = c0 - 5;
c1 = c1 / 255;
c1 = c1 - 5;
c2 = c2 / 255;
c2 = c2 - 5;
}
void loop()
{
PORTB = B11111111; // переводим пины порта B в 1, открывая т.о. ключ (turn on)
delayMicroseconds(200); // wait 200 microseconds
PORTB = 0; // закрывааем ключ, прерывая ток в поисковой катушке (turn off - interrupt circut in search coil )
delayMicroseconds(20);
s0 = analogRead(A0);
s1 = analogRead(A0);
s2 = analogRead(A0);
ss0 = s0 - c0;
if (ss0 < 0)
{
sss0 = 1;
}
ss0 = ss0 / 16;
PORTD = ss0; // посылаем на индикатор (send to LEDs)
delay(1);
ss1 = s1 - c1;
if (ss1 < 0)
{
sss1 = 1;
}
ss1 = ss1 / 16;
PORTD = ss1; // посылаем на индикатор (send to LEDs)
delay(1); ------------------------------------------------------------------------------------------ Add Here
ss2 = s2 - c2;
if (ss2 < 0)
{
sss2 = 1;
}
ss2 = ss2 / 16;
PORTD = ss2; // посылаем на индикатор (send to LEDs)
delay(1); -----------------------------------------------------------------------------------------------Add Here
if ( sss0+sss1+sss2 > 1)
{
digitalWrite(0,HIGH);
delay(2);
if ( sss0+sss1+sss2 > 2)
{
digitalWrite(1,HIGH);
digitalWrite(0,HIGH);
delay(1); ------------------------------------------------------------------------------------Add Here
}
if ( sss0+sss1+sss2 > 3)
{
digitalWrite(2,HIGH);
digitalWrite(1,HIGH);
digitalWrite(0,HIGH);
}
if ( sss0+sss1+sss2 > 4)
{
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
digitalWrite(1,HIGH);
digitalWrite(0,HIGH);
delay(1); -----------------------------------------------------------------------------------------------------Add Here
}
if ( sss0+sss1+sss2 > 5)
{
digitalWrite(4,HIGH);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
digitalWrite(1,HIGH);
digitalWrite(0,HIGH);
delay(1); -------------------------------------------------------------------------------Add Here
}
if ( sss0+sss1+sss2 > 6)
{
digitalWrite(5,HIGH);
digitalWrite(4,HIGH);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
digitalWrite(1,HIGH);
digitalWrite(0,HIGH);
delay(1); ---------------------------------------------------------------------------------------Add Here
}
if ( sss0+sss1+sss2 > 7)
{
digitalWrite(6,HIGH);
digitalWrite(5,HIGH);
digitalWrite(4,HIGH);
digitalWrite(3,HIGH);
digitalWrite(2,HIGH);
digitalWrite(1,HIGH);
digitalWrite(0,HIGH);
delay(1); -----------------------------------------------------------Add Here
sss0 = 0;
sss1 = 0;
sss2 = 0;
}
}
Comment
-
Added Trim. Series? Parallel ? Or Replaced R8 ?
Looks like the output of Op Amp is ringing. That's why the Erratic indications I bet. I don't know what the Hysteresis or trigger level is on the Arduino.
I assume this is BreadBoard work ? Add a Integrator section with off set adjustments and I bet this thing will work quite well taming down the ring and getting the Arduino input stable.
Just Thinking here. Try adding like a 50pF in parallel with R8 to Integrate the signal into the Arduino. See if things tame down some.
Comment
Comment