Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Need some pointers on some code on: February 03, 2013, 06:10:46 am
Thanks a mill

This littel setup I have here seems to work pretty well.. it never seem to miss a step when I move the potentiometer and the only
thing it has a problem( apart from the fade function) is the bounce when I push the switch....Im still busy looking at how to programe the debounce in so iv lifted the delay for now.

Iv seen some arrays where they look somthing like this ( 0,1,0,0,1,1,1) tryed to change it here but no luck. will go thru the array tutorial a bit more.
2  Using Arduino / Programming Questions / Re: Need some pointers on some code on: February 03, 2013, 04:14:21 am
Thanks guys I got my switch to work  smiley

Sorry for all these basic questions but I suffer with dyslexia so takes me a bit of time.
always willing to ask and learn tho.

Iv added in a fade on the 7 segment with the help of  opensource hardware junkies.com...he's site is great. step by step..

Im trying to fade the whole array but it seem to have a problem adding in the 2 to 8 digital pins for some reason.

Also seems to complain about sensorReading now which it had no problem with before I added this new function in.

Thanks


Code:
//Potentiometer controlling 7-segment LED

//declare variables
const int pot = A0; // Potentiometer to Analog pin A0
const int SW = 9; // Switch in 
const int analogInPin = A1;
const int analogOutPins = 2,3,4,5,6,7,8;

int fadeValue = 0;
int outputValue = 0;




void setup() {             
 
  // To 7 segment display
  pinMode(2, OUTPUT); //3-A
  pinMode(3, OUTPUT); //9-B
  pinMode(4, OUTPUT); //6-C
  pinMode(5, OUTPUT); //5-D
  pinMode(6, OUTPUT); //4-E
  pinMode(7, OUTPUT); //2-G
  pinMode(8, OUTPUT); //1-F
  pinMode(9, INPUT_PULLUP); // Switch in 

Serial.begin(9600);
}

void loop() {
 delay(10);
 int sensorReading = analogRead(pot);
 delay(10);
int digitalValue = digitalRead(SW);
 delay (100);
fadeValue = analogRead(analogInPin);
//Map to range of analog out
outputValue = map(fadeValue, 0,1023, 0, 255);
// change the analog out value
analogWrite(analogOutPins, outputValue);
Serial.print("sensor = ");
Serial.print(fadeValue);
Serial.print("\t output = ");
Serial.println(outputValue);
delay(2);
}
// P

  if(sensorReading == 0){
   //write 0
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(4, 1);
   digitalWrite(5, 1);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 0);
   delay(10);
  }
 
  // R
  if(sensorReading > 0 && sensorReading <= 113){
   //write 1
   digitalWrite(2, 0);
   digitalWrite(3, 1);
   digitalWrite(4, 1);
   digitalWrite(5, 1);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 1);
   delay(10);
  }
  // N
  if(sensorReading > 150 && sensorReading <= 226){
   //write 2
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(4, 0);
   digitalWrite(5, 1);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 1);
   delay(10);
  }
  // D
  if(sensorReading > 226 && sensorReading <= 290){
   //write 3
   digitalWrite(2, 1);
   digitalWrite(3, 0);
   digitalWrite(4, 0);
   digitalWrite(5, 0);
   digitalWrite(6, 0);
   digitalWrite(7, 1);
   digitalWrite(8, 0);
   delay(10);
  }
   
   // Segment shows 3

  if(digitalRead(SW)==LOW){
 
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(4, 0);
   digitalWrite(5, 0);
   digitalWrite(6, 1);
   digitalWrite(7, 1);
   digitalWrite(8, 0);
   delay(200);
  }

   
   
   // Segment shows 2
   if(sensorReading > 350 && sensorReading <= 565){
   //write 5
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(4, 1);
   digitalWrite(5, 0);
   digitalWrite(6, 0);
   digitalWrite(7, 1);
   digitalWrite(8, 0);
   delay(10);
  }
 
  // Segment shows L
  if(sensorReading > 565 && sensorReading <= 678){
   //write 6
   digitalWrite(2, 1);
   digitalWrite(3, 1);
   digitalWrite(4, 1);
   digitalWrite(5, 0);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 1);
   delay(10);
  }
}
 
 
3  Using Arduino / Programming Questions / Re: Need some pointers on some code on: February 01, 2013, 05:48:55 pm
I see thanks....yes will be low state

will give it a bash

Thanks
4  Using Arduino / Programming Questions / Re: Need some pointers on some code on: February 01, 2013, 05:23:50 pm
Will state that better......Got a one digit 7 segment and mean it like this

No 0= Park ( P)
No 1= Reverse ( R )
No 2= Nutral (N )
No 3 = Drive ( D )

No 4 = Three  (3)              need the three to work from a switch and blank out drive without moving the potentiometer.
No 5 = Two    (2)
No 6 = Low     (1)
5  Using Arduino / Programming Questions / Re: Need some pointers on some code on: February 01, 2013, 04:55:31 pm
Thats it yes Im looking to have a condition in there of some sort so that it removes that 3 rd display with out moving the potentiometer.

Im busy making a gear shifter display and the gear shifter don't move only in a up and down motion.... got a right movement which
Im trying to use a switch for that
6  Using Arduino / Programming Questions / Re: Need some pointers on some code on: February 01, 2013, 04:38:18 pm
Ok I will...sorry I found it like this on the net
7  Using Arduino / Programming Questions / Re: Need some pointers on some code on: February 01, 2013, 04:35:37 pm
Thanks...like I said Im a real newbie. smiley-zipper

Iv got the numbers 1 to 7 showing as I turn the knob in one direction and when I turn it back it counts back down.

At the 3rd display when turning the knob I need to then flip a switch and it shows up the 4 th digit without turning the knob.

hang on,,, I am the knob here  smiley-grin
8  Using Arduino / Programming Questions / Need some pointers on some code on: February 01, 2013, 04:05:24 pm
Good day to all.

Im a real newbie to all of this coding but Im learning each day   smiley-roll-sweat

I guess this code would seem pretty basic to you guys so here's what Im busy with.

I found this code on the net and Im controlling the 7 segment to count up and down when you turn the potentiometer knob.
Iv changed it a bit to get what I want on the display, cut down the counts to only 7 diffrent numbers aswell.
All works fine but want to add in a switch to turn off the write 3 and turn on write 4 and coil a relay.


Iv still got 5 digital pins open.

Arduino uno
7 segment display ( 1 digit)
Potentiometer
Relays and transistor

Here is the code

Thanks

Code:
//Potentiometer controlling 7-segment LED

//declare variables
const int pot = A0; // Potentiometer to Analog pin A0


void setup() {             
 
  // To 7 segment display
  pinMode(2, OUTPUT); //3-A
  pinMode(3, OUTPUT); //9-B
  pinMode(4, OUTPUT); //6-C
  pinMode(5, OUTPUT); //5-D
  pinMode(6, OUTPUT); //4-E
  pinMode(7, OUTPUT); //2-G
  pinMode(8, OUTPUT); //1-F
 
}

void loop() {
 delay(10);
 int sensorReading = analogRead(pot);
 delay(10);

// Segment shows P on start
  if(sensorReading == 0){
   //write 0
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(4, 1);
   digitalWrite(5, 1);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 0);
   delay(10);
  }
 
  // Segment shows R when potentiometer is turned
  if(sensorReading > 0 && sensorReading <= 113){
   //write 1
   digitalWrite(2, 0);
   digitalWrite(3, 1);
   digitalWrite(4, 1);
   digitalWrite(5, 1);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 1);
   delay(10);
  }
  // Segment shows N
  if(sensorReading > 113 && sensorReading <= 226){
   //write 2
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(4, 0);
   digitalWrite(5, 1);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 1);
   delay(10);
  }
  // Segment shows D
  if(sensorReading > 226 && sensorReading <= 339){
   //write 3
   digitalWrite(2, 1);
   digitalWrite(3, 0);
   digitalWrite(4, 0);
   digitalWrite(5, 0);
   digitalWrite(6, 0);
   digitalWrite(7, 1);
   digitalWrite(8, 0);
   delay(10);
  }
 
  // Need it to turn off the write 3 when a switch is pushed at this point and show write 4
  // Iv removed write 4 here so at this point it skips this number.
  // Also looking for it to strik a relay at the same time
   
   
   
   // Segment shows 2
   if(sensorReading > 452 && sensorReading <= 565){
   //write 5
   digitalWrite(2, 0);
   digitalWrite(3, 0);
   digitalWrite(4, 1);
   digitalWrite(5, 0);
   digitalWrite(6, 0);
   digitalWrite(7, 1);
   digitalWrite(8, 0);
   delay(10);
  }
 
  // Segment shows L
  if(sensorReading > 565 && sensorReading <= 678){
   //write 6
   digitalWrite(2, 1);
   digitalWrite(3, 1);
   digitalWrite(4, 1);
   digitalWrite(5, 0);
   digitalWrite(6, 0);
   digitalWrite(7, 0);
   digitalWrite(8, 1);
   delay(10);
  }
}
 
 
Pages: [1]