Pages: [1]   Go Down
Author Topic: code using photoresistor, 7448 bcd - 7seg converter and arduino error  (Read 624 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure how to attach code so i hope i do it right, this is my first post. I am trying to write code to use a 7448 BCD to seven segment display decoder to use less pins when using a seven segment display and just to make things a little different. Also, I am having the display show a number between 0 and 9 to represent the voltage its letting through. I am getting an error with using a void function. i am new to arduino so i am sure i am doing something very wrong but i would like to learn from this mistake. please help...

void setup()
{
  binaryA(0, 0, 0, 0)
 
  pinMode(7, OUTPUT);
 
  pinMode(8, OUTPUT);
 
  pinMode(9, OUTPUT);
 
  pinMode(10, OUTPUT);
 
  int myInts[] = {num0, num1, num2, num3, num4, num5, num6, num7, num8, num9};
}

void loop()
{
  int lightIn = analogRead(0);
 
  lightIn = map(lightIn, 0, 1024, 0, 9);
 
  myInts[lightIn];
}
     
void binaryA(out1, out2, out3, out4)
{
  if (out1 = 1)             //pin 7; A
  {
    digitalWrite(7, HIGH);
  }
  else
  {
    digitalWrite(7, LOW);
  }
 
  if (out2 = 1)             //pin 10; B
  {
    digitalWrite(10, HIGH);
  }
  else
  {
    digitalWrite(10, LOW);
  }
 
  if (out3 = 1)             //pin 9; C
  {
    digitalWrite(9, HIGH);
  }
  else
  {
    digitalWrite(9, LOW);
  }
 
  if (out4 = 1)              //pin 8; D
  {
    digitalWrite(8, HIGH);
  }
  else
  {
    digitalWrite(8, LOW);
  }
}

void num0()
{
  binaryA(0, 0, 0, 0);
}

void num1()
{
  binaryA(1, 0, 0, 0);
}

void num2()
{
  binaryA(0, 1, 0, 0);
}

void num3()
{
  binaryA(1, 1, 0, 0);
}

void num4()
{
  binaryA(0, 0, 1, 0);
}

void num5()
{
  binaryA(1, 0, 1, 0);
}

void num6()
{
  binaryA(0, 1, 1, 0);
}

void num7()
{
  binaryA(1, 1, 1, 0);
}

void num8()
{
  binaryA(0, 0, 0, 1);
}

void num9()
{
  binaryA(1, 0, 0, 1);
}

* photoresistor_7seg.ino (1.24 KB - downloaded 6 times.)
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 106
Posts: 3764
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

There is more to discuss but for now, you don't need to use if/else statements for your outputs (out1..4), just do digitalWrite(7, out1); . . . digitalWrite(10, out4);

1 = HIGH and 0 = LOW, no need to complicate things. Plus I think your binary is backwards too, but I don't know how you have it wired, so it could be correct.
« Last Edit: May 22, 2013, 05:14:50 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You replied so quick! thank you!! and wow i didnt even think about that, it really saves space, thank you! however, the problem im running into is that it is saying binaryA is void, which i know because i set it to be, but why does it tell me it is an error?
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 106
Posts: 3764
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your program does not know what out1...4 are, are they a byte, an int, your program does not know.

It should be,
void binaryA(byte out1, byte out2, byte out3, byte out4);

Also for these, I would get rid of and just use your "int myInts[]" as,
byte myInt[10][4] = {
{0,0,0,0}, // 0
{0,0,0,1}, // 1
.
.
.
{1,0,0,1} // 9
};

instead of this here
Quote
void num0()
{
  binaryA(0, 0, 0, 0);
}

void num1()
{
  binaryA(1, 0, 0, 0);
}
.
.
.
void num9()
{
  binaryA(1, 0, 0, 1);
}
Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I can tell you are very good at this! thank you alot, i will do this. youve been a huge help, and if i have any other errors i will ask them as well. thanks!
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Now i am getting the error at

"int val = mynum[num];"

That says "invalid conversion from "int" to "int*"

 any ideas?

Quote
int mynum[10][4] = {
    {0, 0, 0, 0},
    {1, 0, 0, 0},
    {0, 1, 0, 0},
    {1, 1, 0, 0},
    {0, 0, 1, 0},
    {1, 0, 1, 0},
    {0, 1, 1, 0},
    {1, 1, 1, 0},
    {0, 0, 0, 1},
    {1, 0, 0, 1}
  };
 
void setup()
{
  binary(0, 0, 0, 0);
 
  pinMode(7, OUTPUT);
 
  pinMode(8, OUTPUT);
 
  pinMode(9, OUTPUT);
 
  pinMode(10, OUTPUT);
 
 
   
}

void loop()
{
  int lightIn = analogRead(5);
 
  int num = map(lightIn, 0, 1024, 0, 9);
 
  int val = mynum[num];
 
  binary(val);
}
     
void binary(int out1, int out2, int out3, int out4)
{
  digitalWrite(7, out1);
  digitalWrite(10, out2);
  digitalWrite(9, out3);
  digitalWrite(8, out4);
}
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int mynum[10][4] = {

That is a 2-dimentional array, so mynum[num] returns a pointer to an array of 4 values.

You will have to use:

Code:
int *val = mynum[num];
Then you would access val[0] thru val[3] for the individual elements.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Queens, New York
Offline Offline
Faraday Member
**
Karma: 106
Posts: 3764
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int mynum[10][4] = {

That is a 2-dimentional array, so mynum[num] returns a pointer to an array of 4 values.

You will have to use:

Code:
int *val = mynum[num];
Then you would access val[0] thru val[3] for the individual elements.

Exactly, so you will need to do something like this,
Code:
int myInts[10][4] =
{
  { 0, 0, 0, 0 },
  { 1, 0, 0, 0 },
  { 0, 1, 0, 0 },
  { 1, 1, 0, 0 },
  { 0, 0, 1, 0 },
  { 1, 0, 1, 0 },
  { 0, 1, 1, 0 },
  { 1, 1, 1, 0 },
  { 0, 0, 0, 1 },
  { 1, 0, 0, 1 }
};

void setup(){
  Serial.begin(9600);
  for(int j = 0; j < 10 ; j++) // cycle through digits
   {
    int * temp = myInts[j];
    for(int i = 0; i < 4; i++) // cycle through data
     {
       Serial.print(*(temp+i));
     }
    Serial.println();
  }
  delay(500);
}


void loop() {
}


« Last Edit: May 23, 2013, 07:20:53 pm by HazardsMind » Logged

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

Pages: [1]   Go Up
Jump to: