Show Posts
Pages: 1 [2] 3 4
16  Using Arduino / Project Guidance / Re: Leonardo Question on: September 01, 2012, 09:07:03 am
Ah ha! After a little digging, I've found this:

 
Quote
When you upload a sketch, you're using the Arduino bootloader, a small program that has been loaded on to the microcontroller on your board. It allows you to upload code without using any additional hardware. The bootloader is active for a few seconds when the board resets; then it starts whichever sketch was most recently uploaded to the microcontroller. The bootloader will blink the on-board (pin 13) LED when it starts (i.e. when the board resets).

That explains the pulsing LED in the beginning. Im still not sure how to ditch the bootloader though...
17  Using Arduino / Project Guidance / Re: Leonardo Question on: September 01, 2012, 08:59:12 am
Could you maybe explain that a little more? I'm a beginner. Is there a way I can accomplish that without any extra hardware?
18  Using Arduino / Project Guidance / Re: Leonardo Question on: August 31, 2012, 09:29:35 pm
Sorry, I thought posting a video would help facilitate the process, guess not. Thanks for posting the summary though, I really need to figure this out. I don't have a schematic but its really simple, just LEDS connected to pwm pins that fade on in succession. Here is the code I'm using:

Code:


int leds[] = {
  3,5,6,9,10,11,13};
int num = 7;


void init_leds(){
  for(int i = 0; i<num; i++){
    digitalWrite(leds[i],LOW);
    pinMode(leds[i], OUTPUT);     
  }
}

void FadeOutLeds(){
  for(int i = 155;i>0;i--){

    for(int j = 0;j<num;j++){
      analogWrite(leds[j],i);
    }
    delay(80);
  }

}

void FadeInLed(int theLed){
  for(int i = 0;i<256;i++){
    analogWrite(theLed,i);
    delay(20);
  }
}


void setup() {               
  // initialize the digital pins as an output.
  init_leds();
}

// the loop routine runs over and over again forever:
void loop() {

  for(int i = 0; i<num;i++){
    FadeInLed(leds[i]);     
  }
  delay(5000);               // wait for 5 seconds
  FadeOutLeds();
  delay(5000); 
}


Im not certain a schematic would help anyway. Im not sure theres technically anything wrong, from what I've read about the Leonardo the bootloader takes 8 seconds to run which is exactly how long the first LEDs pulse for. I just need to know if theres a way to make them stop and have my project begin right away vs. having to wait 8 seconds before the above code is executed.
19  Using Arduino / Project Guidance / Leonardo Question on: August 31, 2012, 03:27:37 pm
For simplicity, I made a video to ask my question:

http://www.youtube.com/watch?v=nXldtGzONus&feature=youtu.be
20  Using Arduino / LEDs and Multiplexing / Re: Simple LED sketch on: August 23, 2012, 10:50:42 pm
baselsw, YOU DA MAN!

Thanks everyone else for the tips!
21  Using Arduino / LEDs and Multiplexing / Re: Simple LED sketch on: August 23, 2012, 03:45:59 pm
Oh sorry, here is the code I tried using. I think I have to remove the void loop to make it work? Maybe its all wrong in general. Try not to laugh when you read it! haha

Code:
/*
 Fade
 
 This example shows how to fade an LED on pin 9
 using the analogWrite() function.
 
 This example code is in the public domain.
 */

int led1 = 3;
int led2 = 5; 
int led3 = 6; 
int led4 = 9; 
int led5 = 10; 
int led6 = 11; 
int led7 = 13;  // the pin that the LED is attached to
int brightness = 0;    // how bright the LED is
int fadeAmount = 5;    // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup()  {
  // declare pin 9 to be an output:
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
  pinMode(led6, OUTPUT);
  pinMode(led7, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop()  {
  // set the brightness of pin 9:
  analogWrite(led1, brightness);   

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness == 0 || brightness == 255) {
    fadeAmount = -fadeAmount ;
   
 
  }
 
for (x = 0; x<256; x=x+1){
analogWrite (led1, x);
delay(10); // take ~2.5 seconds for full fade up
}
for (x = 0; x<256; x=x+1){
analogWrite (led2, x);
delay(10); // take ~2.5 seconds for full fade up
}
for (x = 0; x<256; x=x+1){
analogWrite (led3, x);
delay(10); // take ~2.5 seconds for full fade up
}
for (x = 0; x<256; x=x+1){
analogWrite (led4, x);
delay(10); // take ~2.5 seconds for full fade up
}
for (x = 0; x<256; x=x+1){
analogWrite (led5, x);
delay(10); // take ~2.5 seconds for full fade up
}
for (x = 0; x<256; x=x+1){
analogWrite (led6, x);
delay(10); // take ~2.5 seconds for full fade up
}
for (x = 0; x<256; x=x+1){
analogWrite (led7, x);
delay(10); // take ~2.5 seconds for full fade up
}

}

delay (5000); // hold for 5 seconds
// fade down
for (x=255; x>0; x=x-1){
analogWrite (led1, x);
analogWrite (led2, x);
analogWrite (led3, x);
analogWrite (led4, x);
analogWrite (led5, x);
analogWrite (led6, x);
analogWrite (led7, x);
delay (10);
}
     
 
}

Also, here are errors:

Code:
Fade.cpp: In function 'void loop()':
Fade:46: error: 'x' was not declared in this scope
Fade.cpp: At global scope:
Fade:77: error: expected constructor, destructor, or type conversion before '(' token
Fade:79: error: expected unqualified-id before 'for'
Fade:79: error: expected constructor, destructor, or type conversion before '>' token
Fade:79: error: expected constructor, destructor, or type conversion before '=' token
Fade:91: error: expected declaration before '}' token
22  Using Arduino / LEDs and Multiplexing / Re: Simple LED sketch on: August 23, 2012, 03:25:50 pm
I tried adding that code to the fade sketch and I got a whole mess or errors. I should mention that when it comes to coding I'm very much a beginner. This is for an art project, I tend to do better at the "art" part haha.
23  Using Arduino / LEDs and Multiplexing / Re: Simple LED sketch on: August 23, 2012, 12:12:54 pm
Thanks! I'll try this out when I get home.
24  Using Arduino / LEDs and Multiplexing / Re: Simple LED sketch on: August 23, 2012, 07:54:23 am
Thanks for the reply. Im still not sure how to fade them up one by one though.
25  Using Arduino / LEDs and Multiplexing / Simple LED sketch on: August 23, 2012, 07:14:33 am
Hey guys, newbie question here. I want to use a simple LED sketch that will utilize all 7 PWM ports on the Leonardo. I want to fad up LED 1 and when it reaches maximum brightness begin to fade up LED 2 and so on in succesion until all 7 are lit. 5 seconds after they are all lit I want them all to fade off at the same time. I tried modifying the 'fade' code thats in the examples folder but I didn't get very far. Any help with this would be appreciated
26  Using Arduino / LEDs and Multiplexing / Re: Programming some fading LEDs! on: February 13, 2012, 01:20:10 pm
Thank you for your post, it seems to be working but Im having 2 small issues:

1) For some reason there seems to be a good deal of flickering on each LED as they fade up. I've only got one LED per pin so I'm not sure why this is happeneing. I really need this to be as smooth as possible (its for an art project). I did a project once using sine waves to allow LEDs to fade on pins that arent PWM and it was very smooth, maybe something like that would be better?

2) All the LEDs fade out at the end but I really need them to stay on.

Any help with these would be appreaciated!

27  Using Arduino / LEDs and Multiplexing / Programming some fading LEDs! on: February 10, 2012, 04:56:20 pm
Hey guys, I need some help coding a project I'm working on.

I need a row of LEDs (let’s say 5) to fade up to full brightness one by one. I would like them to fade up slowely so that it takes about 2 seconds to reach full brightness. The problem is, I don’t want the next LED in line to begin fading on once the previous LED has finished, I would like the process to start slightly before that to achieve a more natural and not so staggered look. Let’s say the fade process for LED 2 begins as LED 1 reaches 10% and LED 3 begins when LED 2 reaches 10% and so on... all also attach a picture that will hopefully help depict what I'm trying to do.  When the last LED reaches full brightness and stay there for 5 seconds I would like all LEDs to fade off. Any help would be appreciated!

28  Using Arduino / Programming Questions / Re: sleep mode on: November 28, 2011, 03:47:29 pm
Thanks for the great suggestions! I'm not really sure how to program that though, Im kind of a noob when it comes to C.
29  Using Arduino / Programming Questions / sleep mode on: November 28, 2011, 02:20:34 pm
Hey guys, I’m hoping someone can help me out. I’m interested in mailing an arduino project as a gift. The project is the adafruit waveshield connected to an ambi light sensor. When the sensor detects a certain level of light (when the box is opened) I want it to play a song. Its going to be in transit for about 7 days so I’m assuming I’ll have to use an arduino sleep mode? I’ve been reading up about it but since this is a gift I don’t want to mess it up. Could someone help me modify the code to add a sleep function for 7 days? Also, I’ll be powering the project with 8 AA batteries wired in series.

Code:
#include <FatReader.h>
#include <SdReader.h>
#include <avr/pgmspace.h>
#include "WaveUtil.h"
#include "WaveHC.h"

SdReader card;    // This object holds the information for the card
FatVolume vol;    // This holds the information for the partition on the card
FatReader root;   // This holds the information for the filesystem on the card

uint8_t dirLevel; // indent level for file/dir names    (for prettyprinting)
dir_t dirBuf;     // buffer for directory reads

WaveHC wave;      // This is the only wave (audio) object, since we will only play one at a time

int LDR = 0; // LDR Pin
int val = 0;       // variable to store the value coming from the sensor



// Function definitions (we define them here, but the code is below)
void lsR(FatReader &d);
void play(FatReader &dir);

void setup() {
  Serial.println(analogRead(0));   // print out value of light sensor on analog pin 0
  val = analogRead(LDR);       // read the value from the sensor
  if ( val > 500 ) play(root);
 
  Serial.begin(9600);           // set up Serial library at 9600 bps for debugging
  pinMode(LDR, INPUT);       // declare the LDR as an INPUT
  putstring_nl("\nWave test!");  // say we woke up!
 
  putstring("Free RAM: ");       // This can help with debugging, running out of RAM is bad
  Serial.println(freeRam()); 
 
  // Set the output pins for the DAC control. This pins are defined in the library
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
 
  //  if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you
  if (!card.init()) {         //play with 8 MHz spi (default faster!) 
    putstring_nl("Card init. failed!");  // Something went wrong, lets print out why
    sdErrorCheck();
    while(1);                            // then 'halt' - do nothing!
  }
 
  // enable optimize read - some cards may timeout. Disable if you're having problems
  card.partialBlockRead(true);
 
  // Now we will look for a FAT partition!
  uint8_t part;
  for (part = 0; part < 5; part++) {     // we have up to 5 slots to look in
    if (vol.init(card, part))
      break;                             // we found one, lets bail
  }
  if (part == 5) {                       // if we ended up not finding one  :(
    putstring_nl("No valid FAT partition!");
    sdErrorCheck();      // Something went wrong, lets print out why
    while(1);                            // then 'halt' - do nothing!
  }
 

 
  // Try to open the root directory
  if (!root.openRoot(vol)) {
    putstring_nl("Can't open root dir!"); // Something went wrong,
    while(1);                             // then 'halt' - do nothing!
  }
 
  // Whew! We got past the tough parts.
  putstring_nl("Files found:");
  dirLevel = 0;
  // Print out all of the files in all the directories.
  lsR(root);
}

//////////////////////////////////// LOOP
void loop() {
     root.rewind();
//  play(root);
  val = analogRead(LDR);       // read the value from the sensor
if ( val > 500 ) play(root);
}

/////////////////////////////////// HELPERS

// this handy function will return the number of bytes currently free in RAM, great for debugging!   
int freeRam(void)
{
  extern int  __bss_end;
  extern int  *__brkval;
  int free_memory;
  if((int)__brkval == 0) {
    free_memory = ((int)&free_memory) - ((int)&__bss_end);
  }
  else {
    free_memory = ((int)&free_memory) - ((int)__brkval);
  }
  return free_memory;
}

/*
 * print error message and halt if SD I/O error, great for debugging!
 */
void sdErrorCheck(void)
{
  if (!card.errorCode()) return;
  putstring("\n\rSD I/O error: ");
  Serial.print(card.errorCode(), HEX);
  putstring(", ");
  Serial.println(card.errorData(), HEX);
  while(1);
}
/*
 * print dir_t name field. The output is 8.3 format, so like SOUND.WAV or FILENAME.DAT
 */
void printName(dir_t &dir)
{
  for (uint8_t i = 0; i < 11; i++) {     // 8.3 format has 8+3 = 11 letters in it
    if (dir.name[i] == ' ')
        continue;         // dont print any spaces in the name
    if (i == 8)
        Serial.print('.');           // after the 8th letter, place a dot
    Serial.print(dir.name[i]);      // print the n'th digit
  }
  if (DIR_IS_SUBDIR(dir))
    Serial.print('/');       // directories get a / at the end
}
/*
 * list recursively - possible stack overflow if subdirectories too nested
 */
void lsR(FatReader &d)
{
  int8_t r;                     // indicates the level of recursion
 
  while ((r = d.readDir(dirBuf)) > 0) {     // read the next file in the directory
    // skip subdirs . and ..
    if (dirBuf.name[0] == '.')
      continue;
   
    for (uint8_t i = 0; i < dirLevel; i++)
      Serial.print(' ');        // this is for prettyprinting, put spaces in front
    printName(dirBuf);          // print the name of the file we just found
    Serial.println();           // and a new line
   
    if (DIR_IS_SUBDIR(dirBuf)) {   // we will recurse on any direcory
      FatReader s;                 // make a new directory object to hold information
      dirLevel += 2;               // indent 2 spaces for future prints
      if (s.open(vol, dirBuf))
        lsR(s);                    // list all the files in this directory now!
      dirLevel -=2;                // remove the extra indentation
    }
  }
  sdErrorCheck();                  // are we doign OK?
}
/*
 * play recursively - possible stack overflow if subdirectories too nested
 */
void play(FatReader &dir)
{
  FatReader file;
  while (dir.readDir(dirBuf) > 0) {    // Read every file in the directory one at a time
    // skip . and .. directories
    if (dirBuf.name[0] == '.')
      continue;
   
    Serial.println();            // clear out a new line
   
    for (uint8_t i = 0; i < dirLevel; i++)
       Serial.print(' ');       // this is for prettyprinting, put spaces in front

    if (!file.open(vol, dirBuf)) {       // open the file in the directory
      Serial.println("file.open failed");  // something went wrong :(
      while(1);                            // halt
    }
   
    if (file.isDir()) {                    // check if we opened a new directory
      putstring("Subdir: ");
      printName(dirBuf);
      dirLevel += 2;                       // add more spaces
      // play files in subdirectory
      play(file);                         // recursive!
      dirLevel -= 2;   
    }
    else {
      // Aha! we found a file that isnt a directory
      putstring("Playing "); printName(dirBuf);       // print it out
      if (!wave.create(file)) {            // Figure out, is it a WAV proper?
        putstring(" Not a valid WAV");     // ok skip it
      } else {
        Serial.println();                  // Hooray it IS a WAV proper!
        wave.play();                       // make some noise!
       
        while (wave.isplaying) {           // playing occurs in interrupts, so we print dots in realtime
          putstring(".");
          delay(100);
        }
        sdErrorCheck();                    // everything OK?
//        if (wave.errors)Serial.println(wave.errors);     // wave decoding errors
      }
    }
  }
}
30  Using Arduino / Sensors / Re: AMBI sensor and wave shield on: November 23, 2011, 01:17:44 am
Seems to be working now, thanks for your help!
Pages: 1 [2] 3 4