Pages: [1]   Go Down
Author Topic: compound addition to 7 segment  (Read 443 times)
0 Members and 1 Guest are viewing this topic.
NC,US
Offline Offline
Newbie
*
Karma: 0
Posts: 42
@Weedar_64 #Farmlife
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am very new to using microcontrollers so please excuse any major flaws with the following piece of code. i want 3 analog inputs to add (+=) and the cumulative total (x) to be displayed on a seven segment display. below is where i am so far. i have no idea if this is even close to correct so any assistance would be great.

#
void loop ()
if (analogRead(1) < 20 x += 1;  // if only the low sensor is activated +1 is added to var
if (analogRead(2) < 20 x += 2;  // middle sensor +2
if (analogRead(3) < 20 x += 3;  // top sensor +3
{ (x) == 1
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);}// write '1'
{int (x) == 2
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 1)};// write '2'
 {int (x) == 3
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 1);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 1)};// write '3'
 {int (x) == 4
  digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 1);
 digitalWrite(8, 1)};// write '4'
 {int (x) == 4
 digitalWrite(2, 1);
 digitalWrite(3, 0);
 digitalWrite(4, 1);
 digitalWrite(5, 1);
 digitalWrite(6, 0);
 digitalWrite(7, 1);
 digitalWrite(8, 1)};// write '5'
Logged

South England
Offline Offline
Full Member
***
Karma: 3
Posts: 205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you actually tried compiling that yet and testing the results? I expect you'll see a few errors once you do.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this a college project? You're not the only one asking this question.

I suggest you tackle the problem in steps.

Write a sketch that reads an analog input and prints the value to the Serial port so you can read it on the PC.
Then compare the value against a threshold and decide whether you consider the value 'high' or 'low'.
Then do this for three inputs and print out the number that are 'high'.
Then write a different sketch that displays the digits 0 .. 3 on your display.
Then combine that code into your original sketch to display the number of 'high' inputs each time the number changes.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

NC,US
Offline Offline
Newbie
*
Karma: 0
Posts: 42
@Weedar_64 #Farmlife
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you nailed it. elec. engineering major at NCSU. if you don't mind send me the links to any other forum topics simular to my project (i need all the help i can get) but in regards to the serial output to the pc how would that sketch look? Serial.print.....? also when you say is the value HIGH or LOW do you mean <20 = low >20 = high?
thanks for the help
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Try looking at the example sketches in the IDE. They cover most of what you want. AnalogInOutSerial will get you started. Make use of http://arduino.cc/en/Reference/HomePage. Look at Seven Segment Displays on http://arduino.cc/playground/Main/InterfacingWithHardware#Output too.

Logged

Pages: [1]   Go Up
Jump to: