Show Posts
Pages: 1 ... 56 57 [58] 59 60 ... 197
856  Using Arduino / Project Guidance / Re: Arduino Leonardo Joystick/Gamepad emulation on: October 31, 2013, 04:39:08 am
Yea, you can do that. But it would make things a little easier if you know how to turn it into a function. If not then don't worry about it.
857  Using Arduino / Programming Questions / Re: SoftwareServo.h not being identified ! on: October 30, 2013, 04:01:55 pm
Ok, I see your transmitter code, you didn't divide by 4 directly, but you did map it. Then in your receiver code you then divided by 6. So if you want to get exactly 0 - 180, you either need to map it again in your receiver code or change the data your send it.
858  Using Arduino / Programming Questions / Re: SoftwareServo.h not being identified ! on: October 30, 2013, 09:20:56 am
No, just in your transmitter code, get rid of the "/4". Leave your receiver code as is.
859  Using Arduino / Programming Questions / Re: SoftwareServo.h not being identified ! on: October 29, 2013, 06:13:46 pm
I know the problem. Your transmitter code is using the analogRead("pin") /4. I thought I wrote what that was doing when I showed you my sample. Analog reads value from 0 - 1023. So if you divide it by 4, you get a range from 0 - 255. Now you say your servo only goes to about 42 degs, well if you multiply 42 * 6, you get 252.

So all you need to do is get rid of "/ 4" in your transmitter code, or just map it.
860  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 29, 2013, 08:05:51 am
Well if you can get to that variable in your sketch, you should be good. If it's private, then you need to either make it public or just make a new function to get to it.
861  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 29, 2013, 07:45:53 am
The variable is called "thisByte", it's towards the middle if the code.
862  Using Arduino / Programming Questions / Re: How to send multiple data values from many potentiometers via RF links? on: October 29, 2013, 05:23:04 am
Basically there is a line of code in the VirtualWire library that you need to get to. More importantly, it's the variable "this byte". This variable is equivilant to getting a char from SerialRead. The only thing is, you would need to get to that variable.
863  Using Arduino / Project Guidance / Re: Arduino Leonardo Joystick/Gamepad emulation on: October 28, 2013, 04:45:45 am
Ok, but keep in mind this is not a full working code, it's just a snippet.
Code:
int Toggle = analogRead( A0 );
const int overhead = 3;
// use either cases or if/else statements

if( Toggle == 1023) // Vcc
{
   // your key command here
}

else if( (Toggle / 2) <= 512 + overhead || (Toggle / 2) >= 512 - overhead ) // Vcc / 2
{
  // another key command
}

else // GND
{
  // some other key command
}
864  Using Arduino / Project Guidance / Re: Arduino Leonardo Joystick/Gamepad emulation on: October 28, 2013, 03:07:04 am
SP3T? You can wire the switch to have a different voltage level depending on position. Just use two resistors and wire them between the tabs. One position is GND, the middle position is half voltage and the third is Vcc. Now all you need to do is read it with AnalogRead.
865  Using Arduino / Project Guidance / Re: How to use an exponential function in order to control PWM output? on: October 28, 2013, 01:07:32 am
Ok how about this. You need two variables, a byte and a boolean.
Your setup function is fine. Now you just need two IF statements, one to check if the Byte is greater than 8, and the other if it is less than or equal to zero. That Boolean variable will determine if the LED inhales or exhales, with this: "Boolean variable" ? "byte"++ : "byte"--;  (substitute the "" with your actual variables)

Then with some delay, say 1000, and the pow function. pow(base, exponent), you can control the brightness of the LED on pin 11.
Put it all together and your LED is breathing.

Getting the LED to do this smoothly requires a little more.
866  Using Arduino / Project Guidance / Re: How to use an exponential function in order to control PWM output? on: October 28, 2013, 12:20:24 am
There are thousands of online tutorials, almost all of which are on YouTube. Jeremy Blum makes great tutorials for beginners.
You said you spent 10 hours on this, did you go through each example provided with the Arduino software?
Mainly pointing to Examples -> analog -> fading?

I'm not trying to be rude or anything but 10 hours and you didn't try the analog examples?
867  Using Arduino / Programming Questions / Re: Push button servo control help on: October 27, 2013, 11:52:59 pm
Why not just cut the code down to just one line. Also a state change flag would be better than a 500 millisecond delay, no?

Code:
if (press == LOW)
  {
   servo.write( toggle = !toggle ? 160 : 20); // If press is LOW, toggle is inverted and the output is follows.
  }

     
868  Using Arduino / Project Guidance / Re: How to use an exponential function in order to control PWM output? on: October 27, 2013, 11:38:32 pm
Being that this is an assignment, the usual answer is "Do your own homework". But im nice, and I'll give you a hint to point you in the right direction.

From what I gather, your led must start off dim and increase to full brightness then back down. Well the analogWrite function needs a pin number and a value within a byte (0 - 255) range.  So what you could do is have a value  start at ZERO (or where ever you want to start from) and slowly increment it to full brightness(255), pause for a moment then decrement that value back down to zero. Rinse and repeat. Nothing fancy needed. Also look at the example sketch Blink Without Delay.

Oh and 2 ^ (N - 1) will come in handy.
869  Using Arduino / Project Guidance / Re: password for each user on: October 27, 2013, 08:55:44 pm
I can help with that. See attachment below.

Added:
I just made this sketch, it shows how you can use a LCD with the library. Note, I have a I2C lcd, so you may need to change a few things if you have a regular lcd.
Code:
#include <NewPasswordV2.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x20,20,4);

NewPasswordV2 Mypass;

char Name[10]= {NULL};
char Pword[5] = {'\0'};
char data;

void setup(){
  lcd.init();                      // initialize the lcd
  lcd.backlight();
  Serial.begin(9600);
  Mypass.Init(5); // how long will the password be + null terminator.
  Mypass.AddPassword("1234","Andy");
  Mypass.AddPassword("abcd","Joe");
  Mypass.AddPassword("ASDF","John");
  Mypass.AddPassword("8520","Sam");
  Mypass.AddPassword("1111","Mike");
}

void loop() {
  lcd.setCursor(0,0);
  if(Serial.available() > 0 ){
    data = Serial.read();
    strncpy(Pword, Mypass.EnterData(data),  sizeof(Pword));
   
    switch( Mypass.Check(Pword) )
    {
    case 1:
      lcd.clear();
      lcd.print("Password was found: ");
      lcd.setCursor(0,1);
      lcd.print(Mypass.CheckUser());
      //lcd.println(); 
      break;

    case 0:
      lcd.clear();
      lcd.print("Password not found ");
      EnterNewPassword(); // Comment this out if you do not want to add new passwords
      break;   
    }
  }
}

void EnterNewPassword()
{
  lcd.setCursor(0,1);
  lcd.print("Store it? Y | N: ");
  while(1)
  {
    if(Serial.available() > 0 )
    {
      char choice = Serial.read();
      if(choice == 'y' || choice == 'Y')
      {
        lcd.print(choice);
        lcd.setCursor(0,2);
        lcd.print("Enter name.");
        int cnt = 0;
        while(1)
        {
          if(Serial.available() > 0 )
          {
            char name = Serial.read();
            if(name == '.' || cnt > 9) break;
            else
            {
              Name[cnt++] = name;
              Name[cnt] = '\0';
            }
          }
        }
        Newpassword(Pword,Name);
        break;
      }
      else{
        lcd.print(choice);
        break;
      }
      break;
    }
  }
}

void Newpassword(char * New_Pass, char * New_U)
{
  Mypass.AddPassword(New_Pass, New_U);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Password was added: ");
}
870  Using Arduino / Programming Questions / Re: How do i use analogWrite to cause a DC brush motor to brake on: October 27, 2013, 07:59:50 pm
Proper H-bridge circuit.
http://www.robotroom.com/BipolarHBridge.html
Pages: 1 ... 56 57 [58] 59 60 ... 197