Recent Posts

Pages: 1 [2] 3 4 ... 10
11
Hi! I'm new to Arduino. Know very little about programming, and have tried some ideas but have trouble compiling a working code.After spending days searching the Internet decided to as for help to you guys.
 
So I'm building an Arduino metronome to help me and other musicians keep within the tempo.
As a base i am using a knight rider like code with 7led's.

Code: [Select]


int pinArray[] = {2, 3, 4, 5, 6, 7, 8};
int count = 0;
int timer = 10;

void setup(){
  for (count=0;count<7;count++) {
    pinMode(pinArray[count], OUTPUT);
  }
}

void loop() {
  for (count=0;count<6;count++) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count + 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
  for (count=6;count>0;count--) {
   digitalWrite(pinArray[count], HIGH);
   delay(timer);
   digitalWrite(pinArray[count - 1], HIGH);
   delay(timer);
   digitalWrite(pinArray[count], LOW);
   delay(timer*2);
  }
}



by changing the int timer value - the speed of leds flashing should change. I plan to copy/paste the code 5 times with different timer value to achieve different speeds/tempos

the idea is to use 5difrent pushbuttons to activate 5 different tempos (most often used).

for example - if the button1 is pushed then a tempo1 begins
if a button2 is pushed the first tempo stops and a different one begins and so on!

Would greatly appreciate any help with the code.
Thanks in advance.
13
Nothing, it doesn't work. If I print "path" I read the correct name. But it doesn't create a file.
Why?
14
Sensors / Unable to read switch status i...
Last post by aakash_garg - Today at 08:59 pm
From last few days i was trying to hookup with Arduino as i am building a project which works on ADC and some manual switches.

I put up Two Potentiometer in parallel and connected switches with both of them in series so i can read two different digital value whenever i press either one and process my functionality accordingly.

And i put three led's to pin 11,12,13.

And one more switches for interruption from current execution at pin 9.


CODE:

//Analog pin
const int analogInPin = A0;

//output pin
const int led1 = 11;
const int led2 = 12;
const int led3 = 13;     

//input pin
const int Button = 9;    

//variables
int sensorValue=0;

void setup() {

 pinMode(led1,OUTPUT);
 pinMode(led2,OUTPUT);
 pinMode(led3,OUTPUT);
 pinMode(Button,INPUT);
}

void loop() {
 //read the analog in value:
             
     sensorValue = analogRead(analogInPin);
     
     
     if(sensorValue==500)        //This condition should met when i press first button with first potensiometer.
     {
        digitalWrite(led1,1);       //led1 will glow
        digitalWrite(led2,0);       //led2 will be off

        digitalWrite(led3,1);       //led3 will glow

     }


     if(sensorValue==800)        //This condition should met when i press second button with second potensiometer.
     {
        digitalWrite(led1,0);      //led1 will be off
        digitalWrite(led2,1);      //led2 will glow
        digitalWrite(led3,1);      //led3 will glow
     }

delay(2);
}

Everything is working fine in this code but i needed to include that Button  pin to this code so that whenever i presses it only status of led3 got change and status of both of the led remain same.

I am putting my every effort to make it right but getting unsuccessful in doing so, please help :(
15
Project Guidance / Re: Guidance sought for choosi...
Last post by zoomkat - Today at 08:59 pm
Quote
Granted, initially, all  I want from the website is for it to show me data from just a single sensor, plus relay states.
Well, that would definitely be something for you to start working on.
16
Français / Re: Programme Joystick Arduino
Last post by kriscox - Today at 08:59 pm
Bonsoir

encore un petit soucis dans mon code. Pour information : la shield pour les moteurs est la shield adafruit v1.2.

Au niveau de la vitesse, ça fonctionne. Là, où ça coince c'est le code pour inverser les moteurs dans leur sens de marche en fonction de la position du joystick, donc la fin du programme. J'ai mis le code en entier et en dessous la partie qui pose problème.

Si je prends une seule partie test, les moteurs tournent dans le bon sens, si je prends une autre partie test les moteurs s'inversent bien, mais dès que je cumule deux voire plus de partie test, les moteurs ne tournent plus que dans un sens.
Je me trompe où ?

Code: [Select]


// Librairie Adafruit
#include <AFMotor.h>

// Branchement joystick et moteur
const int x = A0;
const int xMin = 0;
const int xMax = 1023;
const int y = A4;
const int yMin = 0;
const int yMax = 1023;
AF_DCMotor motor_dc_1(1, MOTOR12_2KHZ);
AF_DCMotor motor_dc_2(2, MOTOR12_2KHZ);

// Définition des variables
int lecX, lecY, calX, calY, retX, retY, vit;

void setup () {
// Initialisation port serie
Serial.begin(9600);

// Lecture des valeurs en x et y
lecX = analogRead(x);
lecY = analogRead(y);
}

void loop() {

// Calibration du joystick en 0,0
calX = analogRead(x)-lecX;
calY = analogRead(y)-lecY;


// Réatalonnage x et y de 0,1023 à -255,255
retX = map(calX, xMin, xMax, 0, 512);
retX= constrain(calX, -255, 255);
retY = map(calY, yMin, yMax, -255, 255);
retY = constrain(calY, -255, 255);
Serial.print("X : ");
Serial.print(retX);
Serial.println();
Serial.print("Y : ");
Serial.print(retY);
Serial.println();
delay(50);

if (abs(retX) > abs(retY))
{
vit = abs(retX);
}
else
{
vit = abs(retY);
}


//Vitesse et direction moteurs
if (((lecX) > (1)) && ((lecY) < (-1)))
{
motor_dc_1.setSpeed(vit);
motor_dc_1.run(BACKWARD);
motor_dc_2.setSpeed(vit);
motor_dc_2.run(FORWARD);
}

else if (((lecX) < (-1)) && ((lecY) < (-1)))
{
motor_dc_1.setSpeed(vit);
motor_dc_1.run(FORWARD);
motor_dc_2.setSpeed(vit);
motor_dc_2.run(BACKWARD);
}
else if (((lecX) < (-1)) && ((lecY) > (1)))
{
motor_dc_1.setSpeed(vit);
motor_dc_1.run(BACKWARD);
motor_dc_2.setSpeed(vit);
motor_dc_2.run(FORWARD);
}

else if (((lecX) > (1)) && ((lecY) > (1)))
{
motor_dc_1.setSpeed(vit);
motor_dc_1.run(FORWARD);
motor_dc_2.setSpeed(vit);
motor_dc_2.run(BACKWARD);
}
else
{
motor_dc_1.setSpeed(0);
motor_dc_1.run(RELEASE);
motor_dc_2.setSpeed(0);
motor_dc_2.run(RELEASE);
}
}


Code: [Select]


if (abs(retX) > abs(retY))
{
vit = abs(retX);
}
else
{
vit = abs(retY);
}


//Vitesse et direction moteurs
if (((lecX) > (1)) && ((lecY) < (-1)))
{
motor_dc_1.setSpeed(vit);
motor_dc_1.run(BACKWARD);
motor_dc_2.setSpeed(vit);
motor_dc_2.run(FORWARD);
}

else if (((lecX) < (-1)) && ((lecY) < (-1)))
{
motor_dc_1.setSpeed(vit);
motor_dc_1.run(FORWARD);
motor_dc_2.setSpeed(vit);
motor_dc_2.run(BACKWARD);
}
else if (((lecX) < (-1)) && ((lecY) > (1)))
{
motor_dc_1.setSpeed(vit);
motor_dc_1.run(BACKWARD);
motor_dc_2.setSpeed(vit);
motor_dc_2.run(FORWARD);
}

else if (((lecX) > (1)) && ((lecY) > (1)))
{
motor_dc_1.setSpeed(vit);
motor_dc_1.run(FORWARD);
motor_dc_2.setSpeed(vit);
motor_dc_2.run(BACKWARD);
}
else
{
motor_dc_1.setSpeed(0);
motor_dc_1.run(RELEASE);
motor_dc_2.setSpeed(0);
motor_dc_2.run(RELEASE);
}

}
17
General Electronics / Re: Messing resistor value of ...
Last post by LarryD - Today at 08:57 pm
Maybe:
Put three 1 ohm resitors in parallel will give you .33 ohms.
18
Deutsch / Re: 2 Abläufe gleichzeitig mac...
Last post by BennIY - Today at 08:57 pm
Für Vorgang 1 kann man sich doch einen Sekundentimer einstellen
19
Programming Questions / Re: Inverting Issue
Last post by dlloyd - Today at 08:56 pm
Yep, the internal code for those functions is identical and I don't believe that's the ultimate intention. Can't help with that as this is AVR based ... too bad, as the Arduno Due has complimentary PWM embedded, does not eat up processor cycles and I have an example for that.

@dannyg21 ... What is the application and what range of PWM frequency, duty cycle resolution and timing performance do you require?
20
I just figured that if Atmel  thought it important enough to include that it would be worthwhile.
It is important.  In extremely rare circumstances.  In those rare circumstances it is worthwhile.

Pages: 1 [2] 3 4 ... 10

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy