led bargraph + dc motor+ poti

Processing/Wiring (illetve C) nyelvű programozási fogások, tippek. (AVR-Duino, Arduino, EthDuino, Diecimila, Severino, Nano, LilyPad)
Válasz küldése
Boris.smith
Újonc
Újonc
Hozzászólások: 4
Csatlakozott: 2016. november 12. szombat, 11:25

led bargraph + dc motor+ poti

Hozzászólás Szerző: Boris.smith »

Sziasztok szeretnék össze rakni egy programot de nemtudom össze ileszteni a két dolgot (bargraph+motor) egyszerre seretném őket irányitani egy potival. Külön külön mind kettő müködik de nemtudom össze hozni a kettőt és ebben szeretnék segitséget kérni.
Ezek a nyers példák amiket netről töltötem le .
(motor)
const int POT_PIN = A0;
const int MOTOR_PIN = 9;
int motorSpeed = 0;
int potVal = 0;

void setup()
{
pinMode(MOTOR_PIN, OUTPUT);
}

void loop()
{
potVal = analogRead(POT_PIN);

motorSpeed = map(potVal, 0, 1023, 0, 255);

analogWrite(MOTOR_PIN, motorSpeed);
}


(bargraph)
const int analogPin = A0; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph

int ledPins[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
}; // an array of pin numbers to which LEDs are attached


void setup() {
// loop over the pin array and set them all to output:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
pinMode(ledPins[thisLed], OUTPUT);
}
}

void loop() {
// read the potentiometer:
int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);

// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
}
Avatar
kapu48
Elektronbűvölő
Hozzászólások: 3375
Csatlakozott: 2008. augusztus 29. péntek, 6:00

Re: led bargraph + dc motor+ poti

Hozzászólás Szerző: kapu48 »

Össze dobtam neked:

Kód: Egész kijelölése

// motorBar01.ino

//(motor)
const int POT_PIN = A0;
const int MOTOR_PIN = 9;
int motorSpeed = 0;
int potVal = 0;
//(bargraph)
const int analogPin = A0; // the pin that the potentiometer is attached to
const int ledCount = 10; // the number of LEDs in the bar graph
int sensorReading;
int ledLevel;

int ledPins[] = {
2, 3, 4, 5, 6, 7, 8, 9, 10, 11
}; // an array of pin numbers to which LEDs are attached

void setup()
{
  pinMode(MOTOR_PIN, OUTPUT);
  // loop over the pin array and set them all to output:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT);
  }
}

void loop()
{
  potVal = analogRead(POT_PIN);

  motorSpeed = map(potVal, 0, 1023, 0, 255);

  analogWrite(MOTOR_PIN, motorSpeed);

  // read the potentiometer:
  sensorReading = analogRead(analogPin);
  // map the result to a range from 0 to the number of LEDs:
  ledLevel = map(sensorReading, 0, 1023, 0, ledCount);

  // loop over the LED array:
  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    // if the array element's index is less than ledLevel,
    // turn the pin for this element on:
    if (thisLed < ledLevel) {
      digitalWrite(ledPins[thisLed], HIGH);
    }
    // turn off all pins higher than the ledLevel:
    else {
      digitalWrite(ledPins[thisLed], LOW);
    }
  }
}
Boris.smith
Újonc
Újonc
Hozzászólások: 4
Csatlakozott: 2016. november 12. szombat, 11:25

Re: led bargraph + dc motor+ poti

Hozzászólás Szerző: Boris.smith »

Nagyon szépen köszönöm! pár szóban letudnád irni hogy ilesztetted össze ?
Avatar
kapu48
Elektronbűvölő
Hozzászólások: 3375
Csatlakozott: 2008. augusztus 29. péntek, 6:00

Re: led bargraph + dc motor+ poti

Hozzászólás Szerző: kapu48 »

Semmi különös trükkje nincsen!

Elöl, vannak az állandó és változó értékek összehozva.
A setup-ba, és a loop-ba pedig össze lett fésülve a 2 program.
Minden különösebb optimalizálás nélkül!
Boris.smith
Újonc
Újonc
Hozzászólások: 4
Csatlakozott: 2016. november 12. szombat, 11:25

Re: led bargraph + dc motor+ poti

Hozzászólás Szerző: Boris.smith »

Szia átnéztem töbszöris amit össze raktál nekem, igazábol azt vettem csak észre hogy be másoltad egy kódba a kettőt, nagyon sokszor próbálkoztam vele és nekem nem akart menni, most megprobáltam még ezekhez hozzá adni egy szervót de nekem megint hibát ad ki... ha esetleg tudnál benne segiteni hogy mit rontok el azt megköszönném:)
hibakod:
Arduino: 1.6.12 (Windows 10), Alaplap:"Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

barGraph:3: error: 'Servo' does not name a type

Servo mikroszervo; // mikroszervo nevu szervo objektum

^

C:\Users\Borisz\AppData\Local\Temp\arduino_modified_sketch_188250\barGraph.ino: In function 'void setup()':

barGraph:27: error: 'mikroszervo' was not declared in this scope

mikroszervo.attach(9); // mikroszervo Pin9-re kotve

^

C:\Users\Borisz\AppData\Local\Temp\arduino_modified_sketch_188250\barGraph.ino: In function 'void loop()':

barGraph:41: error: 'mikroszervo' was not declared in this scope

mikroszervo.write(val); // szervopozicio beallitasa

^

exit status 1
'Servo' does not name a type

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Avatar
csegebiga
Chipgyilok
Hozzászólások: 288
Csatlakozott: 2015. március 27. péntek, 21:27

Re: led bargraph + dc motor+ poti

Hozzászólás Szerző: csegebiga »

ez mellett jó lenne látni, hogy milyen kódot szeretnél fordíttatni.
első ránézésre a 'microservo' könyvtárat nem látja a fordító.
Avatar
kapu48
Elektronbűvölő
Hozzászólások: 3375
Csatlakozott: 2008. augusztus 29. péntek, 6:00

Re: led bargraph + dc motor+ poti

Hozzászólás Szerző: kapu48 »

Installing Additional Arduino Libraries:
https://www.arduino.cc/en/Guide/Libraries#toc3
Válasz küldése