Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Help with a random number generating 7 seg display problem! on: January 14, 2013, 02:53:42 am
Code:
  if (num = 0){

Assignment versus comparison.

*facepalm* Sigh... i'm embarrassed to have had to bring this question up. Thank you.

Code:
  pinMode(A0, INPUT);

Why?

That's the input of the potentiometer. Necessary?
2  Using Arduino / Programming Questions / Help with a random number generating 7 seg display problem! on: January 14, 2013, 01:00:26 am
This is probably a very simple fix, and I'll just put the code up:
Code:
int potnum;
int duration;
long randNum;
void setup() {
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
 
  pinMode(A0, INPUT);
 
  Serial.begin(9600);
  randomSeed(analogRead(A1));
}

void loop() {
  randNum = random(10);
  seg(randNum);
}

void seg(long num){
  if (num = 0){
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  Serial.println(num);
  delay(pot());
  }
  if (num = 1){
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  Serial.println(num);
  delay(pot());
  }
  if (num = 2){
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  Serial.println(num);
  delay(pot());
  }
  if (num = 3){
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  Serial.println(num);
  delay(pot());
  }
  if (num = 4){
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  Serial.println(num);
  delay(pot());
  }
  if (num = 5){
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  Serial.println(num);
  delay(pot());
  }
  if (num = 6){
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, LOW);
  Serial.println(num);
  delay(pot());
  }
  if (num = 7){
  digitalWrite(6, LOW);
  digitalWrite(7, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  Serial.println(num);
  delay(pot());
  }
  if (num = 8){
  digitalWrite(6, HIGH);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  Serial.println(num);
  delay(pot());
  }
  if (num = 9){
  digitalWrite(6, HIGH);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, HIGH);
  Serial.println(num);
  delay(pot());
  }
}

int pot(){
  potnum = map(analogRead(A0), 0, 1024, 0, 500);
  return potnum;
}

 

If you go ahead and run this code for yourself, you'll see that it outputs 1, 2, 3...9 and then starts over. I want this to output random numbers on a seven segment display (I'm using an SN7446AN to achieve this).

The whole side of the program that outputs number on a display and the part that determines how quickly these numbers are displayed works fine, but the numbers aren't random! They just go on from 1-9 (it skips 0 for some reason).

So my questions are: Why does the code skip 0 and why aren't the numbers outputted random? I'm fairly new to making subroutines in Arduino, so I'm sure that's where my problem is.

please help! Thank you!
3  Using Arduino / Installation & Troubleshooting / Re: Arduino MEGA 2560 R3 possible broken pin? on: November 29, 2012, 12:48:18 am
Ah, don't worry, I wasn't being defensive or anything smiley Just making sure. And yeah, I'll remember this whole ordeal and I doubt I'll do it again!
4  Using Arduino / Installation & Troubleshooting / Re: Arduino MEGA 2560 R3 possible broken pin? on: November 29, 2012, 12:35:13 am
I haven't been directly powering motors with it, I do use some L293DNE's with it to power some small 5V motors, just to test the chip. I also used some mosfets to make an H-Bridge once, but it was protected with Schlottky diodes. But yes, I do agree with you that I need to be MUCH more careful in the future. And you do think that it's been damaged by me?
5  Using Arduino / Installation & Troubleshooting / Re: Arduino MEGA 2560 R3 possible broken pin? on: November 28, 2012, 11:53:09 pm
It's plugged in the computer in a 3.0 USB port, I think. Nothing's connected to the arduino, and my multimeter isn't faulty, as I just tested it with my bench power supply.
I don't ever remember doing anything that would mess the pins up, but I do have the receipt from Radio Shack. bought it two weeks ago. I'll probably end up replacing it with another. Unless you think it's not faulty!  smiley-wink
6  Using Arduino / Installation & Troubleshooting / Re: Arduino MEGA 2560 R3 possible broken pin? on: November 28, 2012, 11:22:22 pm
Code:
void setup() {
  pinMode(2,OUTPUT);
  pinMode(3,OUTPUT);
  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(13,OUTPUT);
}

void loop() {
  digitalWrite(2,HIGH);
  digitalWrite(3,HIGH);
  digitalWrite(4,HIGH);
  digitalWrite(5,HIGH);
  digitalWrite(6,HIGH);
  digitalWrite(7,HIGH);
  digitalWrite(8,HIGH);
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
}

Then, I go to every pin and test them with my multimeter. I've found that both 5 AND 9 give me low voltages (2.2V for 5, 1.1V for 9). And everything else is ~4.77V, except 8, which is 3.89V. Is that normal?
7  Using Arduino / Installation & Troubleshooting / Arduino MEGA 2560 R3 possible broken pin? on: November 28, 2012, 09:45:09 pm
Well, I'll keep it short and simple: My almost brand new Arduino MEGA 2560 R3 board has a broken digital pin (I think), it always sends 2.2V out even if the BareMinimum sketch is uploaded. What, if anything, can be done about this? It's the digital pin 5. When it's pulled HIGH or LOW, it still always outputs 2.2V. So... What gives?
8  Using Arduino / Programming Questions / Adafruit Motor Shield Code HELP! on: May 30, 2012, 02:56:14 pm
I want to be able to use a TV remote to gradually increase and decrease the speed of motor hooked up to the Adafruit Motor shield, and all my attempts have failed. Here's the code(that doesn't work):
Code:
#include <IRremote.h> // use the library

int receiver = 2; // pin 1 of IR receiver to Arduino digital pin 11

IRrecv irrecv(receiver); // create instance of 'irrecv'

decode_results results;

#include <AFMotor.h>

AF_DCMotor motor(1);

int val = 0;

void setup()

{

  Serial.begin(9600); // for serial monitor output

  irrecv.enableIRIn(); // Start the receiver
 
  motor.setSpeed(0);
 
  motor.run(RELEASE);
}

void translateIR() // takes action based on IR code received


{

  switch(results.value)

  {

    case 0x70: Serial.println("Menu/Exit"); break;

    case 0xA90: Serial.println("Power"); break;

    case 0x290: Serial.println("Mute"); break;

    case 0x90: Serial.println("Ch +"); break;

    case 0x890: Serial.println("Ch -"); break;

    case 0xA70: Serial.println("Select/OK"); break;

    case 0xC90: Serial.println("Vol -"); break;

    case 0x490: Serial.println("Vol +"); break;
   
    case 0x710: Serial.println("Guide"); break;

    case 0x2F0: Serial.println("Up");{
      val = val + 10;
      val = constrain(val, 0, 255);
      Serial.println(val);
      motor.run(FORWARD);
      motor.setSpeed(val);
     
    }break;
   
    case 0xAF0: Serial.println("Down");break;
   
    case 0x2D0: Serial.println("Left");break;
   
    case 0xCD0: Serial.println("Right"); break;

    case 0x910: Serial.println("0"); break;

    case 0x5D0: Serial.println("Info"); break;

    case 0x10: Serial.println("1"); break;

    case 0x810: Serial.println("2"); break;

    case 0x410: Serial.println("3"); break;

    case 0xC10: Serial.println("4"); break;

    case 0x210: Serial.println("5"); break;
 
    case 0xA10: Serial.println("6"); break;
   
    case 0x610: Serial.println("7"); break;
   
    case 0xE10: Serial.println("8"); break;
   
    case 0x110: Serial.println("9"); break;
   
    case 0xD10: Serial.println("Enter"); break;
   
    case 0x9B0: Serial.println("Page Dwn"); break;
   
    case 0x1B0: Serial.println("Page Up"); break;
   
    case 0xA50: Serial.println("Input"); break;
   
    case 0xDD0: Serial.println("-/Prev.Ch"); break;
   
    case 0x425: Serial.println("CC"); break;
   
    case 0xCB0: Serial.println("Play"); break;
   
    case 0x5B0: Serial.println("Record"); break;
   
    case 0x2B0: Serial.println("Pause"); break;
   
    case 0xAB0: Serial.println("Stop"); break;
   
    case 0xEB0: Serial.println("Skip Back"); break;
   
    case 0x6B0: Serial.println("Skip Forward"); break;
   
    case 0xFFFFFFFF: break;

   
    default:  Serial.print("Other button:"); Serial.println(results.value,HEX);

  }

  delay(100);

  //lcd.clear();

}

void loop()

{

  if (irrecv.decode(&results)) // have we received an IR signal?

  {

    translateIR();

    for (int z=0; z<2; z++) // ignore 2nd and 3rd signal repeat

    {

      irrecv.resume(); // receive the next value

    }

  }

}

It compiles correctly, uploads correctly, receives button pushes from the remote correctly, and prints the speed (val) of the motor correctly. Here's the problem: the motor doesn't move! I can get the motor to run just fine with the example code provided with the library, but this code just doesn't work. I am sure that this is a code issue, not a hardware issue. Any help is greatly appreciated!!!!!!!!
9  Using Arduino / Project Guidance / Controlling Arduino with TV remote? Help! on: April 28, 2012, 06:21:52 pm
I'm pretty new to everything that has to do with Arduino, and I'm ready to start with a pretty substantial project: Using a TV remote to control my arduino. I've picked up a Universal remote and an IR sensor. I grabbed this code that gives me the 'codes' that the remote is sending out:
Code:
#include <IRremote.h>

int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}

This will print out a code in hexadecimal form to the serial monitor for each time you press a button. However, the codes it gives off are two-lined, meaning that for each button push, you get two different codes. My question is: where do I go from here? How do i use those codes to, say, turn a LED on and off? turn a servo? Please help, and if this question seems like it's coming from a 'noob' to arduino, its because it is.
Pages: [1]