Pages: [1]   Go Down
Author Topic: I know little about programming, and have a specific question.  (Read 359 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 43
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

My code is receiving an error, and I am using a tutorial.
The tutorial is located at this webpage: http://blog.tinyenormous.com/2009/09/30/17-arduino-nikon-ir-intervalometer-code/

The code that I need help with is as follows:
Code:
void snap(){
int i;
digitalWrite(PIN_STATUS,  1);  
          for(i=0;i”);
          sequence[i] = (sequence[i] * FREQ) / (intervalle * 1000);
          Serial.println(sequence[i]);
      }
}

The error:
Code:
stray '/' in program
« Last Edit: March 18, 2013, 07:25:32 pm by Beatz1337 » Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
    for(i=0;i”);

source of your error
Logged

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

Thank you, now how can I fix it? I am not familiar with this syntax, however, I know lua, and sometimes it gets confusing.
Logged

0
Offline Offline
Sr. Member
****
Karma: 8
Posts: 291
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset



I thought you're going off a tutorial.
Here's instructions on for loop
http://arduino.cc/en/Reference/For
Logged

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

I am, but the tutorial code is incorrect, so could you help me fix this one line of code?
Logged

Westbrook, CT
Offline Offline
Full Member
***
Karma: 2
Posts: 139
"Why should I bother with made-up games when there are so many real ones going on." (c) Kurt Vonnegut
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is exactly how to do it:

Code:
for(i=0; i<100; i++){
     sequence[i] = (sequence[i] * FREQ) / (intervalle * 1000);
     Serial.println(sequence[i]);
}

The i<100 means it would repeat 100 times. Which is repeat until i is no longer smaller than 100. i++ means add one every time the for() function runs.

Read more about the for function:
http://arduino.cc/en/Reference/For
« Last Edit: March 18, 2013, 07:55:09 pm by mixania » Logged

Arduino Uno R3
Mac OSX Lion


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

Thank you, but now I get the error intervalle was not declared in this scope.
If needed, here is the full code:

Code:
// ----- C -------
/**
 * arduino Nikon IR remote
 * @license Creative commons: Attribution-Noncommercial-Share Alike 3.0 (http://creativecommons.org/licenses/by-nc-sa/3.0/)
 * @author Aurelien ANTOINE
 * version 1
 * date 20081217
 * found by ross here http://ilpleut.be/doku.php/code:nikonremote:start
**/
 
#define PIN_STATUS 13
#define PIN_IR_LED 12
#define FREQ 38400  // IR frequence
int hyst=20;
int PotVal = 0;
int count = 0;
int oldVal=0;
 
//shutter sequence (on,off,on,off ... in microsecond)
unsigned long sequence[] = {2000,27830,390,1580,410,3580,400,63200,2000,27830,390,1580,410,3580,400,0};
int seq_l;
 
//oscd is a delay in microsecond used at each oscillation.
int oscd;
 
void oscillate(int pin, unsigned long n, int shine){
int ir_status=0;
while(n>0){
n--;
delayMicroseconds(oscd);
ir_status  =  !ir_status;
digitalWrite(pin,  ir_status && shine); 
}
}
 
void snap(){
int i;
digitalWrite(PIN_STATUS,  1); 
            for(i=0; i<100; i++){
           sequence[i] = (sequence[i] * FREQ) / (intervalle * 1000);
           Serial.println(sequence[i]);
    }
}
 
void setup() {
int min=1, max=100, i;
int last_oscd=0;
unsigned long before, intervalle;
oscd=max;
 
seq_l = sizeof(sequence)/sizeof(unsigned long);
 
pinMode(PIN_STATUS, OUTPUT);
pinMode(PIN_IR_LED, OUTPUT);
Serial.begin(28800);
 
//this "while" will process the best "oscd"
Serial.println("Ready");
while(last_oscd!=oscd){
last_oscd=oscd;
oscd=(min+max)>>1;
 
before=millis();
oscillate(PIN_STATUS, FREQ, 1);
intervalle=millis()-before;
 
if(intervalle >= 1000) max=oscd;
else min=oscd;
 
Serial.print(intervalle);
Serial.print(" : ");
Serial.print(min);
Serial.print("<->");
Serial.println(max);
}
 
Serial.print("oscd: ");
Serial.println(oscd);
 

//rewrite the sequence array, we replace all values in microsecond by the number of oscillation
for(i=0;i<seq_l;i++){

Serial.print(sequence[i]);
Serial.print("->");
sequence[i] = (sequence[i] * FREQ) / (intervalle * 1000);
Serial.println(sequence[i]);
}


}
 
 
void loop() {
//make a photo, wait 10 seconds

PotVal=0;
  for (count = 0; count < 10; count++) { //loops 10 times
    PotVal = (PotVal + analogRead(1))/100; //adds the pot readings together
  }
  //PotVal = (PotVal / 100); // finds average of readings
  Serial.print("Interval is ");
    Serial.print(PotVal);
    Serial.println(" seconds.");
   
snap();
delay(PotVal*1000);
 
}
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

intervelle is declare in loop(), but you are trying to use it in snap(). It should be made global.
Logged

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

Like I said, I have no coding experience besides lua, and so I will need help making this global. What do I need to change?
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Like I said, I have no coding experience besides lua

But you have Google, don't you?

Try googling C++ global scope to see some simple examples.
Logged

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

Ok, and if it gets moved to become a global variable, will it still be able to change as the pot changes?
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3375
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

will it still be able to change as the pot changes?

It doesn't do that now.
Logged

Pages: [1]   Go Up
Jump to: