Go Down

Topic: Will this basic LED circuit work? (Read 2 times) previous topic - next topic

CR123

Code: [Select]
int analogPin = 0;
int readValue = 0;
int redOne = 13;
int redTwo = 12;
int redThree = 11;
int redFour = 10;
int yellowOne = 9;
int yellowTwo = 8;
int yellowThree = 7;
int yellowFour = 6;
int greenOne = 5;
int greenTwo = 4;
int greenThree = 3;
int greenFour = 2;

float temperature = 0;
float temperatureF = 0;
void setup() {
Serial.begin(9600);
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() {
 

  readValue = analogRead(analogPin);
  //Serial.println(readValue);
  temperature = (readValue * 0.0049);
  temperature = temperature * 100;
  temperatureF = (temperature * 1.8) + 32;
  Serial.print(temperature);
  delay(1000);

  if (temperature < 3)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,HIGH);
 
  delay(1000);
}

  if (temperature >= 3 && temperature < 6)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,HIGH);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 6 && temperature < 9)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,HIGH);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 9 && temperature < 12)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,HIGH);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 12 && temperature < 15)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,HIGH);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 15 && temperature < 18)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,HIGH);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 18 && temperature < 21)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,HIGH);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 21 && temperature < 24)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,HIGH);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 24 && temperature < 27)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,HIGH);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 27 && temperature < 30)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,HIGH);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 30 && temperature < 33)
 
{
 
  digitalWrite(redOne,LOW);
  digitalWrite(redTwo,HIGH);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

if (temperature >= 33 && temperature < 36)
 
{
 
  digitalWrite(redOne,HIGH);
  digitalWrite(redTwo,LOW);
  digitalWrite(redThree,LOW);
  digitalWrite(redFour,LOW);
  digitalWrite(yellowOne,LOW);
  digitalWrite(yellowTwo,LOW);
  digitalWrite(yellowThree,LOW);
  digitalWrite(yellowFour,LOW);
  digitalWrite(greenOne,LOW);
  digitalWrite(greenTwo,LOW);
  digitalWrite(greenThree,LOW);
  digitalWrite(greenFour,LOW);
}

}

Runaway Pancake

Uploading...
Code: [Select]

byte index;
int readValue = 0;
int redOne = 13;
int redTwo = 12;
int redThree = 11;
int redFour = 10;
int yellowOne = 9;
int yellowTwo = 8;
int yellowThree = 7;
int yellowFour = 6;
int greenOne = 5;
int greenTwo = 4;
int greenThree = 3;
int greenFour = 2;

float temperature = 0;
float temperatureF = 0;
void setup()
{
Serial.begin(9600);
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);
trialrun();
}

void loop()
{
  readValue = analogRead(A0);
  //Serial.println(readValue);
  temperature = (readValue * 0.0049);
  temperature = temperature * 100;
  temperatureF = (temperature * 1.8) + 32;
  Serial.print(temperature);
  delay(1000);

  if (temperature < 3)   
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,HIGH);
   delay(1000);
  }

  if (temperature >= 3 && temperature < 6)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,HIGH);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 6 && temperature < 9)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,HIGH);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 9 && temperature < 12)
  {
 
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,HIGH);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 12 && temperature < 15)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,HIGH);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 15 && temperature < 18)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,HIGH);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 18 && temperature < 21)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,HIGH);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 21 && temperature < 24)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,HIGH);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 24 && temperature < 27)   
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,HIGH);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 27 && temperature < 30)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,HIGH);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 30 && temperature < 33)
  {
   digitalWrite(redOne,LOW);
   digitalWrite(redTwo,HIGH);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }

  if (temperature >= 33 && temperature < 36)
  {
   digitalWrite(redOne,HIGH);
   digitalWrite(redTwo,LOW);
   digitalWrite(redThree,LOW);
   digitalWrite(redFour,LOW);
   digitalWrite(yellowOne,LOW);
   digitalWrite(yellowTwo,LOW);
   digitalWrite(yellowThree,LOW);
   digitalWrite(yellowFour,LOW);
   digitalWrite(greenOne,LOW);
   digitalWrite(greenTwo,LOW);
   digitalWrite(greenThree,LOW);
   digitalWrite(greenFour,LOW);
  }
}

void trialrun ()
{
  for (index = 2; index < 14; index++)
  {
    digitalWrite(index, HIGH);
    delay(500);
    digitalWrite(index, LOW);
    delay(500);
  }
}



... results?
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

CR123

Problem solved  :) thanks for your help!

Runaway Pancake

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Pedro147

This is a perfect opportunity to ask the question. How do you give someone karma on this forum? Thanks  8)
http://www.pedroduino.com

Runaway Pancake

Pedro147,
Over on the left, with the personal stuff (stats), there's a Green Dot -- click on that when you find a post of value / "meritorious".
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Pedro147

Sorry to labour over this but
Quote
Over on the left, with the personal stuff (stats), there's a Green Dot -- click on that
the left of what page? Thanks
http://www.pedroduino.com

KirAsh4

See attachment ...

Pedro147

Thank you KirAsh4. I should give you a karma point for showing me how to give karma points  8)
http://www.pedroduino.com

Runaway Pancake

"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Pedro147

Nowhere Runaway Pancake, I just needed to be shown exactly where. Thanks for your help too  XD
http://www.pedroduino.com

KirAsh4

Runaway, you didn't go wrong anywhere.  Some of us, myself included, can, at times, be staring at something that's right in front of us, and still not see it.

Pedro147

KirAsh4 - Guilty as accused... I hang my head in shame  :smiley-red:
http://www.pedroduino.com

Go Up