Code for arduino Leonardo dosen't work on arduino mini.

hi guys,

im working on a project for college and my circuit has to read an analog signal from a sensor and then decide my solenoid will open or not. The circuit has to start reading if i press a pushbotton.

the code works fine on arudino leonardo but for my project i need it on arduino mini.

Here is the code:##########################3

int red = 9;
int green=12;
int solenoide=12;
int sensor = A0;
long soma=0;
int first;
int botao = 2;
int nivelbotao;
int array[1000];

///////////////////////////////////////////////////////////////////
void setup() {
pinMode(red, OUTPUT);
pinMode(green, OUTPUT);
pinMode(solenoide,OUTPUT);
pinMode(botao,INPUT);
}

/////////////////////////////////////////////////////////////////
void loop() {

soma=0;
nivelbotao=digitalRead(botao);

if(nivelbotao==HIGH){ // QUANDO O BOTAO ESTA APERTADO FAZ ISTO!!!
digitalWrite(red,HIGH); // acende led azul para sinalizar a leitura
digitalWrite(green,HIGH);
ler_alcool(); // lê o valor de alcool
digitalWrite(red,LOW);
digitalWrite(green,LOW);
delay(1000);

if(soma>(first+200) || soma<=(first+20)){

for(int j=0;j<5;j++){
digitalWrite(red,HIGH); // pisca o led vermelho durante 1s
delay(100);
digitalWrite(red,LOW);
delay(100);
}
}else{

for(int j=0;j<5;j++){
digitalWrite(green,HIGH); // pisca o led verde durante 1s
delay(100);
digitalWrite(green,LOW);
delay(100);
}
digitalWrite(solenoide,HIGH); // abre solenoide
delay(2000);
digitalWrite(solenoide,LOW);
}

}
}

void ler_alcool(){
soma=0;
for(int i=0;i<999;i++){
array*=analogRead(sensor);*
_ soma=soma+array*;_
_
delay(3);_
_
}_
_
first = array[0]; _
_
soma=soma/1000;_
_
}_
_
######################################_
In arduino mini when i press the pushbotton the green and red LED’s go HIGH but never go LOW, so my code dosent work… why??
PLS help me !
THANKS
the_FINAL.ino (2.05 KB)*

hi again, probleme solved.

i tried to take off the function, and put it on the main and now works fine :)

int green=12;
int solenoide=12;

Are these really both using the same pin?!?

fabioverde: In arduino mini when i press the pushbotton the green and red LED's go HIGH but never go LOW, so my code dosent work.... why??

They should stay high for at least 3 seconds since you take 1000 samples and delay 3 milliseconds after each one.

You didn't set the red and green pins to LOW in setup().