• 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
Problem Arduino
#1
Thumbs Up 
Witam wszystkich,

Mianowicie mam taki problem, że zamówiłem Arduino z aliexpress i gdy próbuje w nim programowac wszystko jest okej do czasu gdy użyję jakiejś pętli to wtedy program jakby ją omija i robi to co jest w niej ale nie sprawdza warunku.

Proszę o szybką pomoc.
 
Odpowiedź
#2
Podaj przykładowy program w którym masz ten błąd
[Obrazek: banerelektronika.jpg]



Jeśli pomogłem podziękuj punktem reputacji Wink
 
Odpowiedź
#3
Jednak nie problem jest inny Arduino zczytuje z guzika caly czas stan HIGH a powinno tylko wtedy gdy jest wcisniety, to jest problem guzika czy Arduino
 
Odpowiedź
#4
Jakim stanem zmienisz to ustalasz w programie jeśli low chcesz zmieniać w programie podciągasz do high a switch podpinasz do masy i na odwrót
[Obrazek: banerelektronika.jpg]



Jeśli pomogłem podziękuj punktem reputacji Wink
 
Odpowiedź
#5
O to mój kod w takim razie co jest źle:

Kod:
#include <Wire.h>   // standardowa biblioteka Arduino
#include <LiquidCrystal_I2C.h> // dolaczenie pobranej biblioteki I2C dla LCD

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int buttonPin = 6;
int buttonState = 0;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  // Ustawienie adresu ukladu na 0x27
int sw = 0;

void setup()  
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
lcd.begin(16,2);   // Inicjalizacja LCD 2x16

lcd.backlight(); // zalaczenie podwietlenia
lcd.setCursor(0,0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)
lcd.print("Hello, world!");
delay(500);
lcd.setCursor(0,1); //Ustawienie kursora w pozycji 0,0 (drugi wiersz, pierwsza kolumna)
lcd.print("Program Oskara");
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

}

void loop()
{

buttonState = digitalRead(buttonPin);
if (buttonState==HIGH) {
sw++;
 delay(1000);
if(sw >= 6)
{
sw=0;
 }
}

 if(sw==0) {
 Serial.println("Kolor 1");
setColor(255, 0, 0);
lcd.setCursor(0,0);
lcd.print(buttonState);
}  // red
if (sw==1)
{
   Serial.println("Kolor 2");
   setColor(0, 255, 0);  // green
   lcd.setCursor(0,0);
   lcd.print("kolor Zielony");
}
if(sw==2)
{
   Serial.println("Kolor 3");
setColor(0, 0, 255);  // blue
  lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==3)
{
   Serial.println("Kolor 4");
setColor(255, 255, 0);  // yellow
  lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==4)
{
   Serial.println("Kolor 5");
setColor(80, 0, 80);  // purple
  lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==5)
{
 Serial.println("Kolor 6");
setColor(0, 255, 255);  // aqua
  lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}


}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
  red = 255 - red;
  green = 255 - green;
  blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);  
}
 
Odpowiedź
#6
Kod:
#include <Wire.h> // standardowa biblioteka Arduino
#include <LiquidCrystal_I2C.h> // dolaczenie pobranej biblioteki I2C dla LCD

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int buttonPin = 6;
int buttonState = 0;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Ustawienie adresu ukladu na 0x27
int sw = 0;

void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(buttonPin, OUTPUT);
digitalWrite(buttonPin, 1);
lcd.begin(16,2); // Inicjalizacja LCD 2x16

lcd.backlight(); // zalaczenie podwietlenia
lcd.setCursor(0,0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)
lcd.print("Hello, world!");
delay(500);
lcd.setCursor(0,1); //Ustawienie kursora w pozycji 0,0 (drugi wiersz, pierwsza kolumna)
lcd.print("Program Oskara");
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

}

void loop()
{

buttonState = digitalRead(buttonPin);
if (buttonState==LOW
) {
sw++;
delay(1000);
if(sw >= 6)
{
sw=0;
}
}

if(sw==0) {
Serial.println("Kolor 1");
setColor(255, 0, 0);
lcd.setCursor(0,0);
lcd.print(buttonState);
} // red
if (sw==1)
{
Serial.println("Kolor 2");
setColor(0, 255, 0); // green
lcd.setCursor(0,0);
lcd.print("kolor Zielony");
}
if(sw==2)
{
Serial.println("Kolor 3");
setColor(0, 0, 255); // blue
lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==3)
{
Serial.println("Kolor 4");
setColor(255, 255, 0); // yellow
lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==4)
{
Serial.println("Kolor 5");
setColor(80, 0, 80); // purple
lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==5)
{
Serial.println("Kolor 6");
setColor(0, 255, 255); // aqua
lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}


}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
to spróbuj
[Obrazek: banerelektronika.jpg]



Jeśli pomogłem podziękuj punktem reputacji Wink
 
Odpowiedź
#7
Niestety to też nie pomogło kolory zmieniają się same zamiast tak jak w kodzie na guzik. To jest problem guzika czy Arduino.
 
Odpowiedź
#8
programu do czego masz połączony switch
Kod:
#include <Wire.h> // standardowa biblioteka Arduino
#include <LiquidCrystal_I2C.h> // dolaczenie pobranej biblioteki I2C dla LCD

int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int buttonPin = 6;
int buttonState = 1;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Ustawienie adresu ukladu na 0x27
int sw = 0;

void setup()
{
Serial.begin(9600);
pinMode(buttonPin, INPUT);
pinMode(buttonPin, OUTPUT);
digitalWrite(buttonPin, 1);
lcd.begin(16,2); // Inicjalizacja LCD 2x16

lcd.backlight(); // zalaczenie podwietlenia
lcd.setCursor(0,0); // Ustawienie kursora w pozycji 0,0 (pierwszy wiersz, pierwsza kolumna)
lcd.print("Hello, world!");
delay(500);
lcd.setCursor(0,1); //Ustawienie kursora w pozycji 0,0 (drugi wiersz, pierwsza kolumna)
lcd.print("Program Oskara");
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);

}
sw=255;
void loop()
{

buttonState = digitalRead(buttonPin);
if (buttonState==LOW) {
sw++;
delay(1000);
if(sw >= 6)
{
sw=0;
}
}

if(sw==0) {
Serial.println("Kolor 1");
setColor(255, 0, 0);
lcd.setCursor(0,0);
lcd.print(buttonState);
} // red
if (sw==1)
{
Serial.println("Kolor 2");
setColor(0, 255, 0); // green
lcd.setCursor(0,0);
lcd.print("kolor Zielony");
}
if(sw==2)
{
Serial.println("Kolor 3");
setColor(0, 0, 255); // blue
lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==3)
{
Serial.println("Kolor 4");
setColor(255, 255, 0); // yellow
lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==4)
{
Serial.println("Kolor 5");
setColor(80, 0, 80); // purple
lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}
if(sw==5)
{
Serial.println("Kolor 6");
setColor(0, 255, 255); // aqua
lcd.setCursor(0,0);
lcd.print("kolor Czerwony");
}


}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}
masz po prawiony błąd nie zauważyłem wcześniej
[Obrazek: banerelektronika.jpg]



Jeśli pomogłem podziękuj punktem reputacji Wink
 
Odpowiedź
#9
Do masy i do pinu 6
 
Odpowiedź
#10
'sw' does not name a type
Błąd
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości