Точечная сварка на Arduino UNO

Тема в разделе "Arduino & Shields", создана пользователем mad40, 26 фев 2016.

  1. mad40

    mad40 Нерд

    Озадачил меня тут старшой братик...
    Надо говорит залить в Ардуинку програмульку для самодельной точечной сварки,но лениво код набирать и среду ставить)
    Мне то на работе делать нечего)))
    но мне интересно поиграться и может потом аккумы себе "варить" смогу;)
    Дал распечатку с сайта...я, не будь дурак, скетч оттуда тиснул...но есть интересная проблемка! не могу найти используемую тами библиотеку Switch. Прям даже искал...честно. В источнике ответ не получается добыть.
    понимаю что суть программы проста, но моих убогих познаний не достаточно(((.
    Ссыльку на статью и код скетча привожу ниже. Может кто чем посоветовать?
    http://payalo.net/?newsid=67
    Код в статье кривой судя по каментам...в каментах же приведён рабочий(со слов автора) вариант:
    Код (C++):
    /*
    Note: use the latest Arduino software and install the 3 libraries.
    Arduino spot welder controller
    http://www.avdweb.nl/arduino/hardware-interfacing/spot-welder-controller.html
    Copyright (C) 2012  Albert van Dalen
    This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
    of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License at http://www.gnu.org/licenses .
    Version 1-02-2015
    Program with FTDI programmer, Extra > Board > Arduino Uno
                  <   20ms   >< >sinusMax_us        
                   _____       _____       _____  
    zeroCross   __|     |_____|     |_____|     |__              
                                  _____________        
    weld       __________________|             |____      
                                               
    */

    #include <Arduino.h>
    #include <Streaming.h> // library
    #include <Switch.h> // library
    #include <Albert.h> // library
    const int sinusMax_us = 4583;
    const byte BCDswitch0 = 8;
    const byte BCDswitch1 = 7;
    const byte BCDswitch2 = 6;
    const byte BCDswitch3 = 5;
    const byte weldPin = 2;
    const byte weldButtonPin = 4;
    const byte ledPin = 12;
    const byte zeroCrossPin = 3;
    const int preWeld_ms = 50;
    const int weldPause_ms = 500;
    const int step_ms = 50;
    Switch weldButton(weldButtonPin);
    bool continuously = 0;
    void setup()
    { Serial.begin(9600);
      pinMode(BCDswitch0, INPUT_PULLUP);
      pinMode(BCDswitch1, INPUT_PULLUP);
      pinMode(BCDswitch2, INPUT_PULLUP);
      pinMode(BCDswitch3, INPUT_PULLUP);
      pinMode(weldButtonPin, INPUT_PULLUP);
      pinMode(weldPin, OUTPUT);
      pinMode(ledPin, OUTPUT);
      pinMode(zeroCrossPin, INPUT);
      blinkLed(ledPin, 2);
      digitalWrite(ledPin, 1); // power on indication
      weldButton.poll();
      if(weldButton.on() & BCDswitch()) continuously = 1; // enable continuous welding at switch position 0, attention overheathing 22Ohm!
    }
    void loop()
    { weldButton.poll();
      if(continuously && BCDswitch()==0) weld(weldButton.on()); // continuous welding
      else
      if(weldButton.pushed()) weldCyclus(BCDswitch() * step_ms); // use timer
    }
    void weldCyclus(int weldTime_ms)
    { sinusMax();
      pulseWeld(preWeld_ms);
      delay(weldPause_ms);
      sinusMax();
      pulseWeld(weldTime_ms);
    }
    int BCDswitch()
    { int bcd;
      bitWrite(bcd, 0, !digitalRead(BCDswitch0));
      bitWrite(bcd, 1, !digitalRead(BCDswitch1));
      bitWrite(bcd, 2, !digitalRead(BCDswitch2));
      bitWrite(bcd, 3, !digitalRead(BCDswitch3));
      return bcd;
    }
    void pulseWeld(int ms)
    { weld(1);
      delay(ms);
      weld(0);
      Serial << ms << endl;
    }
    void weld(bool b)
    { digitalWrite(weldPin, b);
      digitalWrite(ledPin, !b);
    }
    void sinusMax()
    { while(digitalRead(zeroCrossPin));
      while(!digitalRead(zeroCrossPin));
      delayMicroseconds(sinusMax_us); // to prevent inrush current, turn-on at the sinus max
    }
     
  2. vvr

    vvr Инженерище

    ПРОЧИТАЙТЕ коммент #20 по вашей ссылке
     
    mad40 нравится это.
  3. mad40

    mad40 Нерд

    во я тугой...
    сейчас испробую и отпишусь тут!
     
  4. mad40

    mad40 Нерд

    Ну разумеется всё в норме...
    Интересное ощущение сейчас получил...админ снеси тему...жесь)