Arduino bcd problem.

Status
Not open for further replies.

duffman

Member
Hi, I've been on here for years, but this is the first time posting. I am getting into arduino and I am running into a silly problem which has blindsided me. I am trying to make a BCD display to show some integer displayed in a variable. In this case it's TempVar. For some reason, the serial display seems to show that TempVar just shows 9 continually. No other number. It should show 2. What is going on here?

 
if (TempVar = 0)

This is assignment...... If you want to test if a variable is 0 then
if (TempVar == 0)..... Double == is the equality operator..
 
One equal sign is an assignment. Two equal signs is a comparison.
In C-language all values other than zero are true. Assignments are evaluated first, then the result is compared against zero. So, in your code all the ifs are evaluated as "true" (except the first one).
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…