| Arduino Forum ::  Members :: green_dog252
 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 Quote from: Coding Badly on January 14, 2013, 01:19:59 amCode:  if (num = 0){Assignment versus comparison.*facepalm* Sigh... i'm embarrassed to have had to bring this question up. Thank you.Quote from: Coding Badly on January 14, 2013, 01:23:05 amCode:  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 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!
 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?