Go Down

Topic: 2x MEGA controlling a relay (Read 684 times) previous topic - next topic

adwsystems

Highest request wins.

Here is what I would do.

Mega 2
1. Find the highest temperature.
2. Determine fan speed
3. Set outputs 1-4 (low->high) based on #2

Mega 1
1. Find the highest tempeature
2. Determine Mega 1 fan speed
3. Read pins 25-28 to determine low->high (if no pins set, then off) to determine Mega 2 fan speed
4. Select higher of the two requests
5. Set fan pins 30-33 based on #4

toxsickcity

Hi

Would you kindly details mega 1 step 4 and 5 a little more?

Using my current fan control code would you add necessary lines of code or alter the lines? For my relay 1

Code: [Select]

unsigned int currentTemp;


    if (min < fan1SetPoint - deltaT) {
      digitalWrite(RELAY1, HIGH);
    }
    if (min < fan2SetPoint - deltaT) {
      digitalWrite(RELAY2, HIGH);
    }
    if (min < fan3SetPoint - deltaT) {
      digitalWrite(RELAY3, HIGH);
    }
    if (min < fan4SetPoint - deltaT) {
      digitalWrite(RELAY4, HIGH);
    }

    if (min > fan1SetPoint + deltaT) {
      digitalWrite(RELAY1, LOW);
    }
    if (min > fan2SetPoint + deltaT) {
      digitalWrite(RELAY2, LOW);
    }
    if (min > fan3SetPoint + deltaT) {
      digitalWrite(RELAY3, LOW);
    }
    if (min > fan4SetPoint + deltaT) {
      digitalWrite(RELAY4, LOW);
    }

adwsystems

#32
Feb 17, 2018, 02:42 am Last Edit: Feb 17, 2018, 02:54 am by adwsystems
Sorry, but it means rewriting the code. By that process you learn the process. Plus it is only a snippet and a lot of information is missing for me do do it.

Your program is a combination of steps 2 and 4. You need to break them up.

Work it step by step and use local variables.

The output of each step should be:
1. Highest temp reading (currently called min, a weird variable name for the highest temp reading)
2. Mega1_fan_speed = 0 to 4
3. Mega2_fan_speed = 0 to 4
4. Fan_Speed = higher of Mega1_fan_speed or Mega1_fan_speed
hint: try if (Mega1_fan_speed>Mega2_fan_speed) then Fan_speed=Mega1_fan_speed else Fan_speed=Mega2_fan_speed
5. Pins 30-33 set based on Fan_Speed as set in step 4. (either use 5 if statements or one 5 case select statement)


toxsickcity

Hi.

Just a q.

0..4 is this code?

adwsystems


Go Up