• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
sterowanie roletami
#15
Dzięki próbowałem "break" ale nie umiem tego ogarnąć moglibyście pomóc? Wszystkie sposoby w jakie próbowałem zatrzymać serwo wyłącznikiem krańcowym działają z bardzo dużym opóźnieniem. A zasłona powinna zatrzymać się natychmiast. Próbowałem ostatnim razem serwo.detach() ale też działa z opóźnieniem.
Kod:
// Adafruit IO REST API access with ESP8266
//
// For use with ESP8266 Arduino from:
//   https://github.com/esp8266/Arduino
//
// Works great with ESP8266 modules like the Adafruit Huzzah ESP:
//  ----> https://www.adafruit.com/product/2471
//
// Written by Tony DiCola for Adafruit Industries.
// MIT license, all text above must be included in any redistribution.
#include <ESP8266WiFi.h>
#include "Adafruit_IO_Client.h"
#include <Servo.h>


// Configure WiFi access point details.
#define WLAN_SSID  "xxxxxx"
#define WLAN_PASS  "xxxxxxxxxxx"

// Configure Adafruit IO access.
#define AIO_KEY    "xxxxxxxxxxxx"


// Create an ESP8266 WiFiClient class to connect to the AIO server.
WiFiClient client;

// Create an Adafruit IO Client instance.  Notice that this needs to take a
// WiFiClient object as the first parameter, and as the second parameter a
// default Adafruit IO key to use when accessing feeds (however each feed can
// override this default key value if required, see further below).
Adafruit_IO_Client aio = Adafruit_IO_Client(client, AIO_KEY);

// Finally create instances of Adafruit_IO_Feed objects, one per feed.  Do this
// by calling the getFeed function on the Adafruit_IO_FONA object and passing
// it at least the name of the feed, and optionally a specific AIO key to use
// when accessing the feed (the default is to use the key set on the
// Adafruit_IO_Client class).
Adafruit_IO_Feed zaslony = aio.getFeed("zaslony");

// Alternatively to access a feed with a specific key:
//Adafruit_IO_Feed testFeed = aio.getFeed("esptestfeed", "...esptestfeed key...");

// Global state to increment a number and send it to the feed.
unsigned int count = 0;
Servo myservo;
int pos = 94;
const int buttonPin = 12;
int buttonState = 0;

void setup() {
 // Setup serial port access.
 Serial.begin(9600);
 delay(10);
 Serial.println(); Serial.println();
 Serial.println(F("Adafruit IO ESP8266 test!"));
pinMode(buttonPin, INPUT_PULLUP);
 // Connect to WiFi access point.
 Serial.print("Connecting to ");
 Serial.println(WLAN_SSID);

 WiFi.begin(WLAN_SSID, WLAN_PASS);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 Serial.println();

 Serial.println("WiFi connected");
 Serial.println("IP address: "); Serial.println(WiFi.localIP());

 // Initialize the Adafruit IO client class (not strictly necessary with the
 // client class, but good practice).
 aio.begin();

 Serial.println(F("Ready!"));
}

void loop() {

 // To read the latest feed value call the receive function on the feed.
 // The returned object will be a FeedData instance and you can check if it's
 // valid (i.e. was successfully read) by calling isValid(), and then get the
 // value either as a text value, or converted to an int, float, etc.
 FeedData latest = zaslony.receive();
 buttonState = digitalRead(buttonPin);
 myservo.attach(2);
 if (latest.isValid()) {
   Serial.print(F("Received value from feed: ")); Serial.println(latest);
   // By default the received feed data item has a string value, however you
   // can use the following functions to attempt to convert it to a numeric
   // value like an int or float.  Each function returns a boolean that indicates
   // if the conversion succeeded, and takes as a parameter by reference the
   // output value.
   int i;
   if (latest.intValue(&i)) {
     Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
   }
   // Other functions that you can use include:
   //  latest.uintValue() (unsigned int)
   //  latest.longValue() (long)
   //  latest.ulongValue() (unsigned long)
   //  latest.floatValue() (float)
   //  latest.doubleValue() (double)
   if (i == 1) {
     Serial.println("Alarm on!");
     for (pos = 94; pos <= 180; pos += 1)
       myservo.write(pos);
     delay(1000);
   }
   else {
     digitalWrite(2, LOW);
   }
 }
   else {
   Serial.print(F("Failed to receive the latest feed value!"));
   digitalWrite(2, LOW);
 }
 if (latest.isValid()) {
   Serial.print(F("Received value from feed: ")); Serial.println(latest);
   // By default the received feed data item has a string value, however you
   // can use the following functions to attempt to convert it to a numeric
   // value like an int or float.  Each function returns a boolean that indicates
   // if the conversion succeeded, and takes as a parameter by reference the
   // output value.
 int i;
 if (latest.intValue(&i)) {
   Serial.print(F("Value as an int: ")); Serial.println(i, DEC);
 }
 // Other functions that you can use include:
 //  latest.uintValue() (unsigned int)
 //  latest.longValue() (long)
 //  latest.ulongValue() (unsigned long)
 //  latest.floatValue() (float)
 //  latest.doubleValue() (double)
 if (i == 2) {
   Serial.println("Alarm on!");
   for (pos = 180; pos >= 94; pos -= 1)
     myservo.write(!pos);
   delay(1000);
 }
 else {
   digitalWrite(2, LOW);
 }
 }
 else {
   Serial.print(F("Failed to receive the latest feed value!"));
   digitalWrite(2, LOW);
 }
 if (buttonState == HIGH) {
   myservo.detach();
 }
else {
}
 if
 // Now wait 10 more seconds and repeat.
 (Serial.println(F("Waiting 10 seconds and then writing a new feed value.")));
 delay(10000);
}

Czy macie jakiś pomysł co zrobić aby stan wyłącznika krańcowego był odczytywany stale, równocześnie z działaniem serwa albo aby pętla przechodziła na tyle szybko aby krańcówka zatrzymywała zasłonę natychmiast. Mógłbym po prostu dać krańcówkę na zasilaniu do serwa, bo prąd nie jest duży ale wolałbym to zrobić programowo zgodnie ze sztuką i przy okazji się czegoś nauczę.
 
Odpowiedź
  


Wiadomości w tym wątku
sterowanie roletami - przez malass - 17-05-2016, 20:36
RE: sterowanie roletami - przez JasQ - 18-05-2016, 18:41
RE: sterowanie roletami - przez adix - 20-05-2016, 00:29
RE: sterowanie roletami - przez Szafa - 13-06-2016, 11:27
RE: sterowanie roletami - przez adix - 13-06-2016, 20:50
RE: sterowanie roletami - przez mavi - 20-06-2016, 12:49
RE: sterowanie roletami - przez pan_statystyka - 21-06-2016, 20:00
RE: sterowanie roletami - przez mavi - 22-06-2016, 01:10
RE: sterowanie roletami - przez adix - 13-07-2016, 23:21
RE: sterowanie roletami - przez Ghost1991 - 16-11-2016, 22:22
RE: sterowanie roletami - przez krn78 - 17-11-2016, 13:53
RE: sterowanie roletami - przez namok - 17-11-2016, 09:52
RE: sterowanie roletami - przez LucaBrasi - 03-01-2018, 21:52
RE: sterowanie roletami - przez Smaczek - 04-01-2018, 10:17
RE: sterowanie roletami - przez LucaBrasi - 06-01-2018, 22:55
RE: sterowanie roletami - przez kaczakat - 05-03-2018, 23:38
RE: sterowanie roletami - przez Alsenas - 20-08-2019, 13:22

Skocz do:


Przeglądający: 1 gości