Show Posts
Pages: [1] 2 3 ... 5
1  Using Arduino / Programming Questions / Re: TM1638 and the keyboard library, how do I assign keystrokes to a HEX/BIN number? on: June 09, 2014, 05:19:01 am
What i am trying to accomplish is using the result of module.getButtons(); in binary format to make something like this: http://arduino.cc/en/Tutorial/EsploraKart
2  Using Arduino / Programming Questions / TM1638 and the keyboard library, how do I assign keystrokes to a HEX/BIN number? on: June 09, 2014, 04:03:39 am
I have got a TM1638 Module and everything works fine so far, but the main reason why I bought it was because it would make a nice additional keyboard for repetetive tasks.

This function gives me the buttons as a HEX number, i.e. 1 for the first, 2 for the second, 4 for the third and so on up to 128.
Code:
#include <TM1638.h>
TM1638 module(4,5,6);

void setup() {
}

void loop() { 
  byte keys = module.getButtons();
}

When displayed as a binary value it exactly represents the buttons as they are pressed, without leading zeros.
My Question now is: How would I assign keys to the HEX or BIN number with the keyboard library?
3  Using Arduino / Programming Questions / Re: Problem understanding non blocking delay via millis() on: April 21, 2014, 02:51:25 pm
Thank you so much! Thats was the crux, i've got it working the way it is supposed to be! Now i can finally get some rest smiley
4  Using Arduino / Programming Questions / Re: Problem understanding non blocking delay via millis() on: April 21, 2014, 02:11:27 pm
At least i found out that the time check doesn't seem to ever start, Serial.println(previousMillis); never happens. I still have got no idea why.

Here's the full version:
Code:
int switchPin = 2;              // switch is connected to pin 2
int pir = 3;                    // pir sensor on pin 3
int potPin = A0;                // brightness control
int statLed = 10;               // mode indicator
int lightOut = 11;              // LED strip will go here

int aVal;                       // variable for reading the pot
int val;                        // variable for reading the pin status
int val2;                       // variable for reading the delayed status
int buttonState;                // variable to hold the button state

long previousMillis = 0;
long interval = 90000;         //wait time for pir mode

int ledState;
int lightMode = 0;              // dimmer mode or pir mode

void setup() {
  pinMode(switchPin, INPUT_PULLUP);
  pinMode(pir, INPUT);
  pinMode(statLed, OUTPUT);
  pinMode(lightOut, OUTPUT);
  Serial.begin(9600);
  buttonState = digitalRead(switchPin);   // read the initial state
}

void loop(){

  val = digitalRead(switchPin);           // checking and debouncing
  delay(10);
  val2 = digitalRead(switchPin);
  if (val == val2) {
    if (val != buttonState) {
      if (val == LOW) {
        if (lightMode == 0) {
          lightMode = 1;                  // go to pir mode
        }
        else {
          lightMode = 0;                  //go to dimmer mode
        }
      }
    }
    buttonState = val;                    // save the new state
  }

  if (lightMode == 0) {                   //dimmer
    aVal = analogRead(potPin);
    analogWrite(lightOut,map(aVal, 0, 1023, 2, 255));
    analogWrite(statLed,map(aVal,0,1023,200,2));
  }

  else{                                  //pir
    digitalWrite(statLed, HIGH);

    // here is my problem

    if(digitalRead(pir) == HIGH){


      digitalWrite(lightOut, HIGH);
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > interval){
        previousMillis = currentMillis;
        Serial.println(previousMillis);
        digitalWrite(lightOut, LOW);

      }

    }
    else{
      digitalWrite(lightOut, LOW);
    }
  }
}
5  Using Arduino / Programming Questions / Re: Problem understanding non blocking delay via millis() on: April 21, 2014, 01:53:34 pm
Well, it's meant to turn off, obviously. Changed the sketch to this:
Code:
    if(digitalRead(pir) == HIGH){
   
     
      digitalWrite(lightOut, HIGH);
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > interval){
        previousMillis = currentMillis;
    digitalWrite(lightOut, LOW);       
   
      }
     
    }
    else{
      digitalWrite(lightOut, LOW);
    }

and changing the interval time still does nothing.
6  Using Arduino / Programming Questions / Re: Problem understanding non blocking delay via millis() on: April 21, 2014, 01:38:43 pm
Do you mean:
Code:
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
?

Because that's the point. I can't figure out how to use that in my sketch.
7  Using Arduino / Programming Questions / Re: Problem understanding non blocking delay via millis() on: April 21, 2014, 01:28:49 pm
I was trying to make use of the blink without delay example, that seemed to make sense. So I guess it doesn't and i started the whole thing out wrong?
8  Using Arduino / Programming Questions / Problem understanding non blocking delay via millis() on: April 21, 2014, 01:21:42 pm
I have got a sketch that reads a button to switch between a dimmer mode and a PIR mode for an LED. The idea is to use a non blocking function for the PIR mode to be able to switch between modes at any time. I have got it kind of working, but somewhere is a mistake, since it doesn't matter whatever value i use for my function, the LED always turns on for the same amount of time. After googling and fiddling around for five hours now, could someone please tell me what's wrong there?

Code:
int switchPin = 2;              // switch is connected to pin 2
int pir = 3;                    // pir sensor on pin 3
int potPin = A0;                // brightness control
int statLed = 10;               // mode indicator
int lightOut = 11;              // LED strip will go here

int aVal;                       // variable for reading the pot
int val;                        // variable for reading the pin status
int val2;                       // variable for reading the delayed status
int buttonState;                // variable to hold the button state

long previousMillis = 0;
long interval = 150000;         //wait time for pir mode

int lightMode = 0;              // dimmer mode or pir mode

void setup() {
  pinMode(switchPin, INPUT_PULLUP);   
  pinMode(pir, INPUT);
  pinMode(statLed, OUTPUT);
  pinMode(lightOut, OUTPUT);

  buttonState = digitalRead(switchPin);   // read the initial state
}

void loop(){

  val = digitalRead(switchPin);           // checking and debouncing
  delay(10);                                       
  val2 = digitalRead(switchPin);     
  if (val == val2) {                             
    if (val != buttonState) {             
      if (val == LOW) {                     
        if (lightMode == 0) {         
          lightMode = 1;                  // go to pir mode
        }
        else {
          lightMode = 0;                  //go to dimmer mode
        }
      }
    }
    buttonState = val;                    // save the new state
  }

  if (lightMode == 0) {                   //dimmer
    aVal = analogRead(potPin);
    analogWrite(lightOut,map(aVal, 0, 1023, 2, 255));
    digitalWrite(statLed,LOW);
  }

  else{                                  //pir
    digitalWrite(statLed, HIGH);

      // here is my problem

    if(digitalRead(pir) == HIGH){
     
      digitalWrite(lightOut, HIGH);
      unsigned long currentMillis = millis();
      if(currentMillis - previousMillis > interval){
        previousMillis = currentMillis;
      }
    }
    else{
      digitalWrite(lightOut, LOW);
    }
  }
}
9  Community / Products and Services / Re: Arduino BT on: October 08, 2013, 11:21:10 am
You could go for a ITeaduino BT instead. It's basically the same thing, just without screw terminals and a ATmega328 instead of an ATmega168.
10  Using Arduino / Programming Questions / Re: Using Arduino Leonardo as joystick on: May 11, 2013, 08:10:51 am
Or maybe i'll stick with this, what doesn't kill me just makes me stronger smiley-grin. It doesn't seem to be my day today, I keep missing out on the simplest of stuff...
11  Using Arduino / Programming Questions / Re: Using Arduino Leonardo as joystick on: May 11, 2013, 07:43:31 am
Exactly. I got used to that. But I still can't get it working, regardless of what i'm trying. Don't even ask about the struct. Always just one of the functions. I feel like a complete idiot  smiley-cry. Seriously, it really can't be that hard!

Edit: I think i'll completely start over based on this: http://arduino.cc/en/Tutorial/EsploraKart
It even has a Video  smiley-lol
12  Using Arduino / Programming Questions / Re: Using Arduino Leonardo as joystick on: May 11, 2013, 05:42:50 am
Well, that looks promising! Of course there will be more inputs, ten when it's done. Arcade style. As i have guessed: I've made dumb logical errors. oldVal is  initialised to 1 on purpose, that seems to be the only proper way to use the internal pullups on an Olimexino-32u4. And the Keyboard.releaseAll(); was pure lazyness, I didn't spent much (if any) time thinking about that... *facepalm*
13  Using Arduino / Programming Questions / Re: Using Arduino Leonardo as joystick on: May 11, 2013, 02:48:45 am
I tried using switch states, but my sketch only works right if only a single function is called. If there's more than one function it repeats the keystrokes as fast as an if-loop  smiley-sad. So walking into a single direction works fine, but that's pretty much pointless in a 3D game. Or in video games in general smiley. Anyway, here's the code I didn't complete for all directions as two won't even work:
Code:
int BUTTON_W = 2;
int BUTTON_A = 5;

void setup() {
  pinMode(BUTTON_W, OUTPUT);
  digitalWrite(BUTTON_W, HIGH);
  pinMode(BUTTON_A, OUTPUT);
  digitalWrite(BUTTON_A, HIGH);
  Keyboard.begin();
}


void loop(){

  forward();
  left();
}

void forward(){

  int val_W = 0;
  int oldval_W = 1;

  val_W = digitalRead(BUTTON_W);

  if (val_W != oldval_W) {

    Keyboard.press('w');

  }

  else {
    oldval_W = val_W;
    Keyboard.releaseAll();
  }   
}

void left(){

  int val_A = 0;
  int oldval_A = 1;

  val_A = digitalRead(BUTTON_A);

  if (val_A != oldval_A) {

    Keyboard.press('a');

  }

  else {
    oldval_A = val_A;
    Keyboard.releaseAll();
  }   
}


I just fail to find out how to send multiple keystrokes, but I bet it's simple and there's a completely dumb error in it.
14  Using Arduino / Programming Questions / Re: Using Arduino Leonardo as joystick on: May 08, 2013, 05:36:27 am
Okay, I'll try that after having lunch smiley. I worked trough that about nine months ago and then had my Arduino collecting dust most off the time. I just have to get back into the matter!
15  Using Arduino / Programming Questions / Re: Using Arduino Leonardo as joystick on: May 08, 2013, 05:18:43 am
I'm trying to make my own game controller that's recognized as a joystick. The demo code works, I did just put the files into the wrong directory. I haven't written my own joystick code yet, but here's my not so well working keyboard code:
Code:
int btn[] = {
  2,3,4,5,6,8};

void setup()
{
    for(int i=0; i<6; i++){
      pinMode(btn[i],OUTPUT);
      digitalWrite(btn[i],HIGH);
    }
    Keyboard.begin();
  }


void loop()
{
  if(digitalRead(btn[5])==0){
    Keyboard.press('0');
    Keyboard.releaseAll();
    delay(250);
  }
  if(digitalRead(btn[3])==0){
    Keyboard.press(216); //left arrow
  }
  if(digitalRead(btn[4])==0){
    Keyboard.press(215); //right arrow
  }

  if(digitalRead(btn[1])==0){
    Keyboard.press(218); //up arrow
  }
  if(digitalRead(btn[1])==0 && digitalRead(btn[4])==0){
    Keyboard.press(218); //up arrow
    Keyboard.press(215); //right arrow
  }

  if(digitalRead(btn[1])==0 && digitalRead(btn[5])==0){
    Keyboard.press(218); //up arrow
    Keyboard.press(216); //left arrow
  }

  else{
    Keyboard.releaseAll();
  }
}


I know, it's awful... smiley-grin
The problem is that it's stuttering because of the repeating which gets me kicked off the server. It makes the game think that I must have got a horrible connection.
Pages: [1] 2 3 ... 5