Pages: [1] 2 3   Go Down
Author Topic: analog input issuses  (Read 3164 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi guy and girls. im new to the arduino.
i have theuno rev 3
im having an issue with using the anolg input for my project.
i have 3 push buttons and two switches
they each run threw a 10k pull down resister.
but only two push button read on the arduino.
and neather of the switches.
what could the issue be?
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 108
Posts: 3778
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

post your code
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26618
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

And a schematic.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok here it is



in the drawing pin 11 becomes A4
                          10 becomes A3
                          5               A1
                          4               A2
                          2               A0


other thing you should probly know is that i made a boo boo and stuck 9v threw the 5 inputs this is y im trying to use the analog input.
silly me.
and the transistor i changed to a relay
and also tried to add in a wake up funtion for the camera with a second relay.

so i may well have messed this whole thing up.







* inter2cctdiagram.png (12.49 KB, 1149x733 - viewed 55 times.)
* sketch_interrev5.ino (9.91 KB - downloaded 22 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the code dont fit
so here is the first half

Code:
//pins on the arduino.
const int shutterPin = 3;  //output to camera
const int startLEDPin = 13;  //visual display of timelapse running
const int upPin = A1;  //input for up button
const int downPin = A2;  //input for down button
const int minutePin = A3;  //visual display of minutes yes/no (seconds in active if not HIGH)

const int HDRPin = A4; //visual display of HDR yes/no
const int startPin = A0; //input for begin button
const int wakepin = 12;

//for displaying digits on the 7-segment LEDs.
const int clockPin = 6;
const int serialOnesPin = 7;
const int serialTensPin = 8;
const int serialHundsPin = 9;

const int a=1;
const int b=2;
const int c=4;
const int d=8;
const int e=16;
const int f=32;
const int g=64;

byte digits[10];
byte inf[3];
byte pic[3];
byte intvl[3];

//interval settings
long interval = 10; //seconds
long oldInterval;
long intervalCounter = 0;  //this variable and the next allow for incrementation of the interval
long intervalStep = 10;  //so that the timelapse can be interrupted at any time.

int infoDelay = 1500;
int wakeup = 300;          //time to activate wakeup (focus)
int wakewait =200;         //time between wake and shutter

//number of pictures to be taken total
boolean changeNumPics = true;
int oldNumPics = 0;
int numPics = 0; //total number of pictures, 0 means infinite.
long numPicsChanged = infoDelay;
long numPicsTimeout = 2000; //ms
int count = 0;  //keeps track of number of pictures.

//variables for different options (HDR and minute/second)
boolean minute = false;
int minuteMultiplier = 1;
boolean HDR = false;  //flag for hdr timelapses

//button logic and debouncing
boolean start = false; //records whether timelapse should be going or not.
int startReading;  //reads start button input
int prevStartReading = LOW;  //stores last start button input for latching.
int upReading;  //reads up/down button input
int prevUpReading = LOW;  //stores last up button input for latching.
int downReading;  //reads down button input
int prevDownReading = LOW;  //stores last down button input for latching.

long pressStartTime = 0;  //stores time of last button state change for debouncing
long pressUpTime = 0;  //ditto
long pressDownTime = 0;  //ditto
long debounceDelay = 100;  //debounce wait period in ms

//miscellaneous variables
boolean sleeping = false;
long activityTime = 0;
long sleepTime= 300000; //ms, time to wait before sleeping. (300000 ms = 5 min)
int waitTime;
int safetyDelay = 50; //ms, wait period when camera pin is HIGH to give the camera time to respond
int HDRsafetyDelay = 1500; //ms, time the camera pin is HIGH for fast-fire HDR pictures to be taken

void setup(){
  //declare the pins as inputs or outputs
  pinMode(shutterPin, OUTPUT);
  pinMode(wakepin, OUTPUT);
  
  pinMode(HDRPin, INPUT);
  pinMode(startPin, INPUT);
  pinMode(startLEDPin, OUTPUT);
  pinMode(clockPin, OUTPUT);
  pinMode(serialOnesPin, OUTPUT);
  pinMode(serialTensPin, OUTPUT);
  pinMode(serialHundsPin, OUTPUT);
  pinMode(upPin, INPUT);
  pinMode(downPin, INPUT);
  pinMode(minutePin, INPUT);
  
  //define which segments of the 7-segment LEDs should light for different digits
  digits[0] = a + b + c + d + e + f;
  digits[1] = b + c;
  digits[2] = a + b + g + e + d;
  digits[3] = a + b + g + c + d;
  digits[4] = f + g + b + c;
  digits[5] = a + f + g + c + d;
  digits[6] = a + f + g + c + d + e;
  digits[7] = a + b + c;
  digits[8] = a + b + c + d + e + f + g;
  digits[9] = a + b + f + g + c + d;
  //define the segments for displaying "inf"
  inf[0] = b + c;
  inf[1] = e + g + c;
  inf[2] = a + f + g + e;
  //define the segments for displaying "pic"
  pic[0] = a + b + g + f + e;
  pic[1] = inf[0];
  pic[2] = a + f + e + d;
  //define the segments for displaying "int"
  intvl[0] = b + c;
  intvl[1] = inf[1];
  intvl[2] = f + g + e + d;
  
  Serial.begin(9600);
  //start/stop button is an interrupt so that it's always active
  attachInterrupt(0, checkStart, RISING);
  
  //give some parameter information.
 
 displayPIC();
 delay(infoDelay);
 
 if (numPics == 0){
   displayINF();
 }
 else{
   displayDEC(numPics/10);
 }
  
  while (changeNumPics){
      oldNumPics = numPics;
      checkUp();
      checkDown();
      Serial.println(numPics);
      if (oldNumPics != numPics){
         if (numPics == 0){
           displayINF();
         }
         else{
           displayDEC(numPics/10);
         }
      }
      if (millis() - numPicsChanged > numPicsTimeout){
        changeNumPics = false;
      }
}
  displayINT();
  delay(infoDelay);
  displayDEC(interval);
}

void loop(){
  //if timelapse is not running, display the current interval between pictures and be ready
  //to accept input that will change the value of interval.
  if (!start){
    minute = digitalRead(minutePin);
    oldInterval = interval;
    checkUp();
    checkDown();
    if (oldInterval != interval){  //helps reduce flicker in the display
      displayDEC(interval);
    }
  }
  
  while ((count <= numPics || numPics == 0) && start == true){
    sleeping = (millis()-activityTime > sleepTime);
    Serial.println("sleep status");
    Serial.println(sleeping, DEC);

    //set wait time, depending on status of HDR flag.  
    HDR = digitalRead(HDRPin);
    if (HDR){
      waitTime = HDRsafetyDelay;
    }
    else{
      waitTime = safetyDelay;
    }      
      
    //take a picture
      digitalWrite(wakepin, HIGH);   //turn wakeup/focus on
      
      delay(wakeup);                 //keep focus
      
      digitalWrite(wakepin, LOW);    //turn wakeup off
      
      delay(wakewait);               //wait
      
      digitalWrite(shutterPin, HIGH);

      delay(waitTime);

      digitalWrite(shutterPin, LOW);
      count++;
  
    //display picture number
    if (sleeping){
      displayOFF();
      }
    else{
      displayDEC(count);
    }
    
    //wait the user-set interval
    if (minute){
      minuteMultiplier = 60;
    }
    else{
      minuteMultiplier = 1;
    }

      intervalCounter = 0;
      while((intervalStep*intervalCounter) < (((interval*1000)*minuteMultiplier)-(2*waitTime)) && start){
        delay(intervalStep);
        intervalCounter++;
      }
      
    //if the timelapse is to be stopped (or is finished), reset the counter to prepare it for the next timelapse.
    if (!start || count == numPics){
      displayDEC(interval);
      count = 0;
      start = false;
      digitalWrite(startLEDPin, start);
    }
  }      
}


////////////////////////////////////////////
//////Other Functions///////////////////////
////////////////////////////////////////////

//function to check the state of the start button and change the variables/LED state correspondingly
void checkStart(){
  if (!changeNumPics){
  activityTime = millis();
  if (sleeping){
    sleeping = false;
    displayDEC(count);
  }
  else{
  //if (millis() - pressStartTime > debounceDelay){ **debounce handled by hardware.
    start = !start;
    digitalWrite(startLEDPin, start);
    //pressStartTime = millis();
  //}
  }
  }
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

second half


//function to check the state of the up button and increment interval accordingly.
void checkUp(){
  upReading = digitalRead(upPin);
  if (upReading == HIGH && prevUpReading == LOW && millis() - pressUpTime > debounceDelay){
    activityTime = millis();
    if (changeNumPics){
      if (numPics >= 9950){  //allows variable to wrap around.
        numPics = 0;
      }
      else{
        numPics += 50;
        numPicsChanged = millis();
      }
    }
    else{
      if (interval >= 999){
        interval = 0;
      }
      else{
        interval += 1;
      }
    }
    pressUpTime = millis();
  }
  prevUpReading = upReading;
}

//function to check the state of the down button and increment interval accordingly.
void checkDown(){
  downReading = digitalRead(downPin);
  if (downReading == HIGH && prevDownReading == LOW && millis() - pressDownTime > debounceDelay){
    activityTime = millis();
    if (changeNumPics){
      if (numPics <= 0){  //allows variable to wrap around.
        numPics = 9950;
      }
      else{
        numPics -= 50;
        numPicsChanged = millis();
      }
    }
    else{
      if (interval <= 0){
        interval = 999;
      }
      else{
        interval -= 1;
      }
    }
    pressDownTime = millis();
  }
  prevDownReading = downReading;
}


//function to display a 3 digit number on 7-segment displays.
void displayDEC(int i){
  for (byte bitMask = 128; bitMask > 0; bitMask >>= 1){
   digitalWrite(clockPin, LOW);
   digitalWrite(serialOnesPin, bitMask & ~digits[i%10] ? HIGH : LOW);
   digitalWrite(serialTensPin, bitMask & ~digits[(i/10%10)] ? HIGH : LOW);
   digitalWrite(serialHundsPin, bitMask & ~digits[i/100] ? HIGH : LOW);
   digitalWrite(clockPin, HIGH);
  }
}

//function to display "inf" on 3 7-segment displays.
void displayINF(){
  for (byte bitMask = 128; bitMask > 0; bitMask >>= 1){
    digitalWrite(clockPin, LOW);
    digitalWrite(serialOnesPin, bitMask & ~inf[2] ? HIGH : LOW);
    digitalWrite(serialTensPin, bitMask & ~inf[1] ? HIGH : LOW);
    digitalWrite(serialHundsPin, bitMask & ~inf[0] ? HIGH : LOW);
    digitalWrite(clockPin, HIGH);
  }
}

void displayPIC(){
  for (byte bitMask = 128; bitMask > 0; bitMask >>= 1){
    digitalWrite(clockPin, LOW);
    digitalWrite(serialOnesPin, bitMask & ~pic[2] ? HIGH : LOW);
    digitalWrite(serialTensPin, bitMask & ~pic[1] ? HIGH : LOW);
    digitalWrite(serialHundsPin, bitMask & ~pic[0] ? HIGH : LOW);
    digitalWrite(clockPin, HIGH);
  }
}
void displayINT(){
  for (byte bitMask = 128; bitMask > 0; bitMask >>= 1){
    digitalWrite(clockPin, LOW);
    digitalWrite(serialOnesPin, bitMask & ~intvl[2] ? HIGH : LOW);
    digitalWrite(serialTensPin, bitMask & ~intvl[1] ? HIGH : LOW);
    digitalWrite(serialHundsPin, bitMask & ~intvl[0] ? HIGH : LOW);
    digitalWrite(clockPin, HIGH);
  }
}
void displayOFF(){
  for (byte bitMask = 128; bitMask > 0; bitMask >>= 1){
    digitalWrite(clockPin, LOW);
    digitalWrite(serialOnesPin, HIGH);
    digitalWrite(serialTensPin, HIGH);
    digitalWrite(serialHundsPin, HIGH);
    digitalWrite(clockPin, HIGH);
  }
}
  
///////////////////////////////////////////[
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26618
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
for (byte bitMask = 128; bitMask > 0; bitMask >>= 1){
    digitalWrite(clockPin, LOW);
    digitalWrite(serialOnesPin, HIGH);
    digitalWrite(serialTensPin, HIGH);
    digitalWrite(serialHundsPin, HIGH);
    digitalWrite(clockPin, HIGH);
  }
That's a pretty roundabout way of doing eight iterations. In the absence of comments, any particular reason?

Quote
the code dont fit
probably because there's too much of it.
« Last Edit: December 11, 2012, 02:43:42 pm by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

not sure y its like that.
its a code that i found on the net.
im new so only know the very basics.
if you know a better way im all ears.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 108
Posts: 3778
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where did you find that code, because that is a LOT of code.
Do you have a link?
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

sadly i did not keep the link.
guess i should have.
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 108
Posts: 3778
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could you retrace your steps?
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 310
Posts: 26618
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

For now, all you need to show is whether or not a number of inputs work.
So, write a small sketch that does just that, using known I/O mechanisms, like Serial.print.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks ill try that.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

other thing you should probly know is that i made a boo boo and stuck 9v threw the 5 inputs this is y im trying to use the analog input.
silly me.
and the transistor i changed to a relay
and also tried to add in a wake up funtion for the camera with a second relay.

so i may well have messed this whole thing up.

Quite possibly. A relay and a transistor are not usually interchangeable. What you're trying to do does not sound especially hard, but the picture you posted shows a fairly complex circuit, and I don't know whether you're getting even the basics right let alone wiring up things like that correctly.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Newbie
*
Karma: 0
Posts: 18
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the cct worked.
problems came after i put the 9v battery in the wrong side.
now i just cant get the analogs to work.
Logged

Pages: [1] 2 3   Go Up
Jump to: