author

azureblue

Inbox View Profile
7Comments

Tell us about yourself!

Achievements

course completion badge
Large Motors ClassClass Complete!
  • azureblue commented on daily3dprinting's instructable CNC Arduino Plant Growing Machine8 months ago
    CNC Arduino Plant Growing Machine

    Anytime you find yourself writing the same code more than once, it's a good idea to ask yourself if you could make it into a function (or a loop).If you get stuck, comment on here again and I'll try to help out.

    I didn't try to reproduce all of your code, so I have left the lighting bit out. I was just trying to show a neater way of doing the same thing (test, move, water) to each of the plants, without repeating the code over and over (basically what kcribbs is asking). Your own version of loop() was fine - call one function to handle the lighting, call another to handle the watering logic. To turn my suggestion into a complete solution, you'd want/need to reintroduce some of your own code. I'd suggest copy/paste it into the Arduino editor, fix the indentation and then see if it's clearer.One thing that might be worth considering is putting a big delay into the main loop (1 minute? 10 minutes? 1 hour?) - this is quite a slow moving system (plants take a while to dry out), so you don't really n...

    see more »

    I didn't try to reproduce all of your code, so I have left the lighting bit out. I was just trying to show a neater way of doing the same thing (test, move, water) to each of the plants, without repeating the code over and over (basically what kcribbs is asking). Your own version of loop() was fine - call one function to handle the lighting, call another to handle the watering logic. To turn my suggestion into a complete solution, you'd want/need to reintroduce some of your own code. I'd suggest copy/paste it into the Arduino editor, fix the indentation and then see if it's clearer.One thing that might be worth considering is putting a big delay into the main loop (1 minute? 10 minutes? 1 hour?) - this is quite a slow moving system (plants take a while to dry out), so you don't really need to keep checking every few milliseconds (or whatever speed loop() would naturally run at). Not a major problem in your case, but if it was a battery powered system you'd want to use as little power as possible.

    I don't know how well this is going to format, but here's a partial code rewrite, with plenty of comments inline to explain the motivation behind it:int p1 = A0; //Plant One Hygrometer int p2 = A1; //Plant Two Hygrometer int p3 = A2; //Plant Three Hygrometer int p4 = A3; //Plant Four Hygrometer // Group together all attributes related to a single plantstruct plant { int hygrometer; // Analog pin the hygrometer is connected to int threshold; // How moist the plant likes to be int stepOffset; // Where the plant is};// A relic from 'C' (the language) that allows us to work in terms// of 'Plant's rather than having to type 'struct plant' all the timetypedef struct plant Plant; // Description of all of our plants. The values inside {...} are assigned// to the properties of a ...

    see more »

    I don't know how well this is going to format, but here's a partial code rewrite, with plenty of comments inline to explain the motivation behind it:int p1 = A0; //Plant One Hygrometer int p2 = A1; //Plant Two Hygrometer int p3 = A2; //Plant Three Hygrometer int p4 = A3; //Plant Four Hygrometer // Group together all attributes related to a single plantstruct plant { int hygrometer; // Analog pin the hygrometer is connected to int threshold; // How moist the plant likes to be int stepOffset; // Where the plant is};// A relic from 'C' (the language) that allows us to work in terms// of 'Plant's rather than having to type 'struct plant' all the timetypedef struct plant Plant; // Description of all of our plants. The values inside {...} are assigned// to the properties of a Plant in the same order (so for the first plant,// hygrometer = p1, threshold = 700, stepOffset = 50)const Plant plants[] = { {p1, 700, 50}, {p2, 600, 900}, {p3, 700, 1750}, {p4, 900, 2550}};// Have the compiler work out how many plants we've got by dividing the size of// the data structure which describes *all* the plants by the size of the structure// to describe *one* plant. This way, we can add or remove plants (in the array above)// and we won't need to rememeber to update the count.const int plantCount = sizeof(plants) / sizeof(Plant);// Declare functions that we'll define the implementation of further down the file// Breaking code up into small chunks of closely related functionality makes our code:// a) easier to understand when we come back to it a week/month/year from now// b) easier to change (maybe re-order things? change how a decision is made?)// c) at the highest level, it reads more like a sentence. All the fine details are// hidden away further down. (See loop(), below)void moveToEndStop();void moveBySteps(int steps);// Specifying a default value gives us the option of asking for a specific// delay if we want to (runWaterPump(7000)) or getting the default if we don't// care (runWaterPump())void runWaterPump(int duration=10000);void loop() { // By having several descriptions of *what* we want to do something to, // but only one definition of *how* to do it, we no longer have to update // four pieces of code to make one change. This makes for less error-prone code. for (int plant = 0; plant < plantCount; plant++) { // Get the dampness int moisture = analogRead(plants[plant].hygrometer); // If *this* plant needs water, move to it if (moisture > plants[plant].threshold) { moveToEndStop(); moveBySteps(plants[plant].stepOffset); // ... and water it runWaterPump(); } } }void moveToEndStop() { // Logic for finding moving to end stop here}void moveBySteps(int steps) { // Logic for moving a set amount here}void runWaterPump(int duration) { // Logic for running the water pump here}I hope the comments explain things, but ask questions if they don't.

    Wow. Unfortunately the Instructables formatter thinks it knows best and it removes all leading white spaces, ruining any attempt to indent code for readability.

    View Instructable »
  • azureblue commented on mosivers's instructable Word Clock Controlled by 114 Servos9 months ago
    Word Clock Controlled by 114 Servos

    25 seconds into the first video, I knew you were German! Can you guess how? Native English speakers say "back and forth". Germans tend to say "forth and back", which doesn't really change the meaning, but does make you easy to spot ;-)It's an excellent build. Do you know the average power consumption? And which time transition causes the peak power usage?

    View Instructable »