Show Posts
Pages: 1 [2] 3 4 ... 6
16  Using Arduino / Programming Questions / PWM dimming + Fan output on: December 17, 2012, 06:25:49 pm
Hi everyone,

I am making a sketch to control a lamp with leds and a cooling fan. Until now I have been using this sketch below, where booleans let me divide the pwm numbers into different parts.. When the button is pressed the light gets brighter, a bit like those ikea touch lamps.
Now, I need another pin to connect a fan (i am using pin 10 at the moment) to the circuit. This fan should be on when the leds are on but should also stay on for some seconds when the leds will be switched off.. just to cool down the lamp.
I have tried using millis, but didn't get really far. Maybe is the case to change my previous bit of code too? Maybe I should use different cases to dim the leds instead?
I know it's very simple, but would be good to head someones help asap!



//

int buttonPin = 4;
int ledPin = 9;
int fanPin = 10;
boolean lastButton = LOW;
boolean currentButton = LOW;
int ledpwmLevel = 0;
int fanpwmLevel = 0;

void setup()
{
  pinMode(buttonPin, INPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(fanPin, OUTPUT);
  Serial.begin(9600);
}

boolean debounce(boolean last)
{
  boolean current = digitalRead(buttonPin);
  if (last != current)
  {
    delay(5);
    current = digitalRead(buttonPin);
  }
  return current;
}

void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledpwmLevel = ledpwmLevel + 85;
    Serial.println("BUTTON");
  }
  lastButton = currentButton;

  if (ledpwmLevel > 255) ledpwmLevel = 0;
  fanpwmLevel =
  analogWrite(ledPin, ledpwmLevel);

}
17  Using Arduino / Programming Questions / Re: Music Shield and Proximity Control: coding issues? on: June 12, 2012, 12:21:12 pm
Ok, big update. Using the Play() function as it was would have not allow me to just play a file, as that function never returns. I have written a new one (JPlay) and now it works much better. I can now get the patch to run as many times as I want... everytime the distance sensor goes over the threshold the file play for all it's length.

Now, would be good to write something to avoid the file to play twice if the person remains in front of the sensor. Is this clear enough? or should I try explain it differently?

first attempt which doesn't work (it plays the file when something is close to the sensor, but it will play it twice if the sensor is still covered)


#include <avr/io.h>
#include "config.h"
#include "filesys.h"
#include "player.h"
#include "vs10xx.h"
#include "record.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //pin2-Rx,pin3-Tx(note: pin3 is actually later used as volume down input)

const int analogPin = A5;
const int ledPin = 0;
const int threshold = 300;

int sensor = A5;

void setup()
{
  Serial.begin(9600);
  InitSPI();
  InitIOForVs10xx();
  InitIOForKeys();
  InitIOForLEDs();
  InitFileSystem();
  Mp3Reset();
}

void loop() {


  //Serial.println("loop");   
  Serial.println(analogRead(analogPin));
  int pippo = 1;

  while (analogRead(analogPin) > threshold) {
    Serial.println("paperino");
    if (pippo = 1) {
      JPlay();
      pippo = 0;
    }

  }
}


18  Using Arduino / Programming Questions / Re: Music Shield and Proximity Control: coding issues? on: June 12, 2012, 10:12:13 am
All the digital Pins are in use by the the board, so I am not checking the state with an Led.. which anyhow was pointless. I haven't made any change.
19  Using Arduino / Programming Questions / Re: Music Shield and Proximity Control: coding issues? on: June 11, 2012, 08:50:05 am
Yes that's make sense. That's also why the Music Shield is not using them I guess..
My problem is still there though. Anyone?

This seems to be the function I have to use, but I am not really sure how to read this reference..
http://code.google.com/p/musicshield/source/browse/branches/arduino+code/music/player.cpp

void Play()
{
  playingState = PS_NEXT_SONG;

  currentFile = 1;

 
  //cyclely play
  while(1)
  {

         //CheckPlay();
         //CheckKey();
         AvailableProcessorTime();
         
         if(1 ==playStop)
         {
                if(OpenFile(currentFile))
                {       
                        //if open failed, then try it again
                        if(OpenFile(currentFile))
                        {
                                playStop = 0;
                                playingState = PS_NEXT_SONG;
                                currentFile = 1;
                                continue;
                        }
                }
               
                PlayCurrentFile();
                if (playingState == PS_PREVIOUS_SONG) currentFile--;
            if (playingState == PS_NEXT_SONG) currentFile++;
        if (currentFile==0) currentFile = 1;
        //if (playingState == PS_END_OF_SONG) playingState = PS_NORMAL;
                Mp3SoftReset();
         }
  }
}


20  Using Arduino / Programming Questions / Re: Music Shield and Proximity Control: coding issues? on: June 11, 2012, 08:28:33 am
no it doesn't cause I think the pin is always in use somehow.. it's always on... but if I use pin13 and delete the Music Shield part then yes it does work.
21  Using Arduino / Programming Questions / Music Shield and Proximity Control: coding issues? on: June 11, 2012, 05:27:50 am
Hi,

I am using an Arduino UNO and a Seeedstudio Music Shield (http://seeedstudio.com/wiki/Music_Shield) to run a very simple project, which is giving me some problems anyway.. Basically, when someone is close enough to a proximity sensor (Analog5), a stored sound file should start playing. The file would play till the end (2.30 min), then the arduino would wait some time and start the process again so that the next person that comes in will enjoy the same treat.
You have to imagine that the sensor is in front of a mirror and the file plays only (but for all it's length) when someone approches it.. Of course this is quite hard cause if someone will remain in front of the mirror for longer time then the file will play again... but that is part of the game I guess.

Here is my code. At the moment I can get the file to play when the sensor goes under a threshold but then it won't play again a second time.. the process kind of freezes it self after a first reproduction. ..thanks a lot!!


 #include <avr/io.h>
 #include "config.h"
 #include "filesys.h"
 #include "player.h"
 #include "vs10xx.h"
 #include "record.h"
 #include <SoftwareSerial.h>
 SoftwareSerial mySerial(2, 3); //pin2-Rx,pin3-Tx(note: pin3 is actually later used as volume down input)

 const int analogPin = A5;
 const int ledPin = 1;
 const int threshold = 400;

 void setup() {

  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
 
  InitSPI();
  InitIOForVs10xx();
  InitIOForKeys();
  InitIOForLEDs();
  InitFileSystem();
  //VsSineTest();
  Mp3Reset();
 }

 void loop() {


  int proximityValue = analogRead(analogPin);
    Serial.println(proximityValue);
   
  if (proximityValue > threshold) {
    digitalWrite(ledPin, HIGH);
  }
  else {
    digitalWrite(ledPin, LOW);
    Play();
  }



 }



22  Topics / Interactive Art / Seedstudio Music Shield + Proximity Sensor? on: June 07, 2012, 06:17:21 am
Hi everyone,

I am trying to do something really simple, and would like to see if someone has done it already. Basically, I need to trigger a sound file stored in my Music Shield (http://seeedstudio.com/wiki/Music_Shield) using a proximity sensor. So, when the analog reading goes above a level the file is triggered... if you have done something similar with other sensors that would be good too as it is just a normal analogRead.

Thanks a lot!
23  Development / Other Hardware Development / Re: 8 Channel Shield... how? on: May 10, 2012, 10:46:43 am
For those interested I found a nice tutorial here: http://www.hobbyist.co.nz/?q=interfacing-relay-modules-to-arduino . My shield does looks exactly the same except that I have 8 relays instead of 4. Job done!
24  Development / Other Hardware Development / Re: 8 Channel Shield... how? on: May 10, 2012, 10:04:09 am
I tried looking for it but it doesn't really come up with anything. It needs 5 volts to switch the relays on and off.. or at least that's what it said on the ebay page.. please have a look: http://tinyurl.com/7sjtbw8

on the relays it says Songle: 10A 250v AC, 10A 125v AC, 10A 30v DC, 10A 28V DC. So at least I should be sure that it works well with AC right? What I don't understand is why there are three screw connectors for each relay.. what's in the middle?

Thanks
25  Development / Other Hardware Development / 8 Channel Shield... how? on: May 10, 2012, 09:33:40 am
Hello everyone,

I have just received a 8 Channel relay pcb bought on ebay for just 8£ (http://tinyurl.com/7sjtbw8), but I am not too sure how to connect it up with arduino. I have used relays before but i just want to be sure not to blow anything so.. would anyone give me a hand with this?

The 10 pins on one side are numbered 1-8 (arduino pins i guess) and a gnd and a vcc (how much power would this need?)

I need to connect various radios to power them on and off (via software). They are both dc powered (9, 12 volts), both mains ac (220).


Every advice would be very welcome! Thanks a lot!

26  Using Arduino / Interfacing w/ Software on the Computer / Re: Processing + Hacked printer .. where to start? on: April 05, 2012, 08:38:01 am
I could add a feature to lift the pen, but yes at the moment is always touching the paper..

I have seen many of those etch a sketch projects, as I said my trial was not supposed to be anything new.. it's just that I never tried anything in this direction until now. Well, if anybody knows code I could start with that would be very appreciated...
27  Using Arduino / Interfacing w/ Software on the Computer / Processing + Hacked printer .. where to start? on: April 04, 2012, 08:04:33 pm
Today I decided to open an old epson printer I bought ages ago and try rewiring it to my arduino. Luckily it didn't take long before I got it to work and run smoothly using a Adafruit motorshield and replacing the cartridges with just a simple marker.
I managed to get the first results by programming clumsy lines of code... basically describing each movement the motors would have to do (I am using one of the motors to control the X and one to make the page go up and down) in order to draw simple shapes. Nothing new really, it was just good to explore this area!

But now I was wondering if someone could tell me where I could start to get this thing going, getting more interesting. I was planning of using processing, which I never really used before, to draw something or to open a bitmap and then transform that into motors movements for the "printer"..

Any advice will be very welcome! Thanks a lot! 
28  Using Arduino / Motors, Mechanics, and Power / Big steppers: what's the best way to use them? on: April 03, 2012, 06:44:29 pm
Hi there,

I am taking my first steps with stepper motors ( smiley-cool) and I would love to try and use three big one I've salvaged from an old photocopy machine:
3.7v 1A
4.08V 1.7A
3.8V 2A
all with 1.8 Deg/Step specifics.. What would be the best way to control them? I already have a ladyada motorshield but since I would need external power anyhow I was considering building my own circuit for it. Any advice is more then welcome!

Thanks to everybody!
29  Using Arduino / General Electronics / How to connect sensors on a rotating object ? on: January 12, 2012, 06:51:39 am
Hello,

I am trying to figure out what is the best why to connect sensor (or low voltage connections anyway) on a rotating object. My first trial will be positioning the sensor on a ceiling fan' blade. How can I wire the sensor so that the signal will "come out" with the other wires (from the shaft, then routed with the power cables somewhere)?

I am sure this is a silly question for lots of you, but I don't even know what is the real name to call it! At the moment I am trying to make a conductive strip fixed on the shaft which will connect to the wire coming from the blade. It's not very precise and it will surely get messy when it comes to 3 wires (i am gonna use hall effect sensors)..

Any suggestions? thaaanks
30  Using Arduino / Project Guidance / Re: How to control a Ceiling Fan? (edit!) on: January 12, 2012, 06:43:10 am
Thanks to everyone for the help. I am gonna try setting something up during this weekend and I will update the post after hand..
Pages: 1 [2] 3 4 ... 6