Show Posts
Pages: 1 ... 38 39 [40] 41 42 ... 228
586  Using Arduino / Programming Questions / Re: Question 433mhz transmitter and receiver. on: March 24, 2014, 07:00:24 pm
Try this, it should work now. You should see on onboard led next to pin 13 come on when you press a button.
Code:
#include <VirtualWire.h>

void setup()
{
  Serial.begin(9600);      // Debugging
  Serial.println("setup");

  // inisial IO dan ISR
  vw_set_ptt_inverted(true); // dibutuhkan untuk DR3100
  vw_setup(2000);     // Bits per sec
  vw_set_tx_pin(3);

  pinMode(8, INPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(11, INPUT);
}

void loop()
{
  char *msg;

  if(digitalRead(8) == HIGH)
  {
    msg = "1";
    digitalWrite(13, true);
  }
  else if(digitalRead(9) == HIGH){
    msg = "2";
    digitalWrite(13, true);
  }
  else if(digitalRead(10) == HIGH)
  {
    msg = "3";
    digitalWrite(13, true);
  }
  else if(digitalRead(11) == HIGH)
  {
    msg = "4";
    digitalWrite(13, true);
  }
  else
    msg = "0";
   
  vw_send((uint8_t *)msg, strlen(msg));
  vw_wait_tx();
  digitalWrite(13, false);

}
587  Using Arduino / Programming Questions / Re: Question 433mhz transmitter and receiver. on: March 24, 2014, 06:34:13 pm
If you press the button, does it go HIGH or LOW?

This here in the transmitter code is setting the buttons HIGH and wanting them to go low to send out a message. You might need to comment this part out, but first what do you have?
Quote
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
588  Using Arduino / Programming Questions / Re: Question 433mhz transmitter and receiver. on: March 24, 2014, 05:18:08 pm
Try this.

Tx:
Code:
#include <VirtualWire.h>

void setup()
{
  Serial.begin(9600);      // Debugging
  Serial.println("setup");

  // inisial IO dan ISR
  vw_set_ptt_inverted(true); // dibutuhkan untuk DR3100
  vw_setup(2000);     // Bits per sec
  vw_set_tx_pin(3);

  pinMode(8, INPUT);
  pinMode(9, INPUT);
  pinMode(10, INPUT);
  pinMode(11, INPUT);

  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
}

void loop()
{
  char *msg;

  if(digitalRead(8) == LOW)
  {
    msg = "1";
    digitalWrite(13, true);
  }
  else if(digitalRead(9) == LOW){
    msg = "2";
    digitalWrite(13, true);
  }
  else if(digitalRead(10) == LOW)
  {
    msg = "3";
    digitalWrite(13, true);
  }
  else if(digitalRead(11) == LOW)
  {
    msg = "4";
    digitalWrite(13, true);
  }
  else
    msg = "0";
   
  vw_send((uint8_t *)msg, strlen(msg));
  vw_wait_tx();
  digitalWrite(13, false);

}


Rx:
Code:
#include <VirtualWire.h>
char lastchar = '0';

void setup()
{
  Serial.begin(9600);    //Debugging
  Serial.println("setup");

  //Inisial IO dan ISR
  vw_set_ptt_inverted(true); // ibutuhkan untuk DR3100
  vw_setup(2000);     //Bits per sec
  vw_set_rx_pin(2);
  vw_rx_start();       //memulai receiver

  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

  if (vw_get_message(buf, &buflen))
  {
    // menerima pesan checksum
    Serial.print("Menerima: ");
    Serial.print(buf[0]);
    Serial.print(" ");

    if(buf[0] == '1' && buf[0] != lastchar )
    {
      digitalWrite(8, !digitalRead(8));
    }
    else if(buf[0] == '2' && buf[0] != lastchar )
    {
      digitalWrite(9, !digitalRead(9));
    }
    else if(buf[0] == '3' && buf[0] != lastchar )
    {
      digitalWrite(10, !digitalRead(10));
    }
    else if(buf[0] == '4' && buf[0] != lastchar )
    {
      digitalWrite(11, !digitalRead(11));
    }
    lastchar = buf[0];
  }
}
589  Using Arduino / Programming Questions / Re: Question 433mhz transmitter and receiver. on: March 24, 2014, 02:54:07 pm
What LED is flashing, the onboard LED next to pin 13?
590  Using Arduino / Programming Questions / Re: Question 433mhz transmitter and receiver. on: March 24, 2014, 12:48:17 pm
(5V)-------------{button}---x-------<resistor>------(Gnd)
                                                          |
                                                          |
                                                  (Ard pin)
591  Using Arduino / Programming Questions / Re: Question 433mhz transmitter and receiver. on: March 24, 2014, 04:15:45 am
Did you remember the pulls own resistors for each of the buttons?
592  Using Arduino / Programming Questions / Re: Question 433mhz transmitter and receiver. on: March 24, 2014, 03:29:14 am
So wait you want to toggle it? Press once = ON, press again = OFF?
593  Using Arduino / Programming Questions / Re: Question 433mhz transmitter and receiver. on: March 24, 2014, 12:40:16 am
Your receiver code was turning the LEDs off because they were being told to turn off at the beginning of every loop. However, if you only turn off the LED when you don't receive anything then they should not flicker.

RX
Code:
#include <VirtualWire.h>

void setup()
{
    Serial.begin(9600);    //Debugging
    Serial.println("setup");

    //Inisial IO dan ISR
    vw_set_ptt_inverted(true); // ibutuhkan untuk DR3100
    vw_setup(2000);     //Bits per sec
    vw_set_rx_pin(2);
    vw_rx_start();       //memulai receiver

pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
}

void loop()
{
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;

    if (vw_get_message(buf, &buflen))
    {
    int i;

/*lampu menyala sebagai indikator pesan terkirim*/
        digitalWrite(13, true);
       // menerima pesan checksum
       Serial.print("Menerima: ");
   
    for (i = 0; i < buflen; i++)
    {
        Serial.print(buf[i]);
        if(buf[i] == '1'){digitalWrite(8, HIGH);}
        if(buf[i] == '2'){digitalWrite(9, HIGH);}
        if(buf[i] == '3'){digitalWrite(10, HIGH);}
        if(buf[i] == '4'){digitalWrite(11, HIGH);}
        Serial.print(" ");
    }
    Serial.println("");
        digitalWrite(13, false);

   }
   else // if you get nothing, then LED off.
   {
     digitalWrite(8, LOW);
     digitalWrite(9, LOW);
     digitalWrite(10, LOW);
     digitalWrite(11, LOW);
   }
}
594  Using Arduino / Project Guidance / Re: Button Help, Up, Down, Select on: March 23, 2014, 11:54:35 pm
So something like this?
Code:
#include <LiquidCrystal.h>

LiquidCrystal lcd(7,8,9,10,11,12);


#define factor 1000
//Set buttons pin numbers
const byte incrementButton = 5;
const byte decrementButton = 6;
const byte SelectButton = 3;

//Global variables
boolean incrementState = 0; //variable that will read the increment button (either HIGH or LOW)
boolean decrementState = 0; //variable that will read the decrement button (either HIGH or LOW)
int counter = 0; //variable that will store the count
boolean lastIncrementState = 0;
boolean lastDecrementState = 0;
boolean selectState = 0;
boolean lastSelectState = false, State = false, ON = true;
int led = 13;
unsigned long Ontime = 0, Offtime = 0;
byte TimeOn = 1, TimeOff = 1;

void setup()
{
  lcd.begin(16, 2); //set up the LCD's number of columns and rows:
  pinMode(led, OUTPUT);
  pinMode(incrementButton, INPUT); //set incrementButton as INPUT
  pinMode(decrementButton, INPUT); //set decrementButton as INPUT
  pinMode(SelectButton, INPUT); //set decrementButton as INPUT

  lcd.setCursor(1,0);
  lcd.print("Time On"); //print a message on the LCD "Time On"
  lcd.setCursor(1,1); //Set the cursor at row 2 to print next line
  lcd.print("Time Off"); ////print a message on the LCD "Time Off"
  lcd.setCursor(0,1);
  lcd.print(">");
}//end of setup

void loop()
{
  incrementState = digitalRead(incrementButton); //read the increment button state
  decrementState = digitalRead(decrementButton); //read the decrement button state
  selectState = digitalRead(SelectButton); //read the Select button state

  if(selectState !=  lastSelectState) // lastSelectState will need to be declaired boolean too at the top of your code.
  {
    if(selectState == HIGH)
    {
      // Notice I put this in here and not outside the if statement.
      State = !State; // also declare boolean at the top of your code. Set to false
    }
    if(State)
    {
      lcd.setCursor(0,0);
      lcd.print(">");
      lcd.setCursor(0,1);
      lcd.print(" ");
    }
    else
    {
      lcd.setCursor(0,0);
      lcd.print(" ");
      lcd.setCursor(0,1);
      lcd.print(">");
    }

    lastSelectState = selectState;
  }

  if(incrementState != lastIncrementState) //compare increment button state to its last state
  {
    if(incrementState == HIGH)//increment button is pressed
    {
      //increment the counter
      if(State == HIGH)
        TimeOn++;
      else
        TimeOff++;
      delay(20); //debounce delay
    }
    lastIncrementState = incrementState;
  }

  if(decrementState != lastDecrementState)//compare decrement state to its lastState
  {
    if(decrementState == HIGH)//decrement button is pressed
    {
      //decrement the counter
      if(State == HIGH)
        TimeOn--;
      else
        TimeOff--;

      delay(20); //debounce delay
    }
    lastDecrementState = decrementState;
  }

  lcd.setCursor(10, 0);
  lcd.print(TimeOn); //print it on serial monitor       
  lcd.print("   "); //3 blank spaces
  lcd.setCursor(10, 1);
  lcd.print(TimeOff); //print it on serial monitor
  lcd.print("   "); //3 blank spaces

  LEDState();
}//end of loop

void LEDState()
{
  if(millis() - Ontime > (TimeOn * factor) && ON == true) // ON in this case looks to see if the LED itself is on. So before this IF statement is true, the LED is on
  {
    Offtime = millis(); // Notice it does not say Ontime, but instead it says Offtime. This is because when the
                        // LED is OFF, we want to start the timer to turn it back ON.
    digitalWrite(led, LOW);   // turn off LED
    ON = false;
  }
  if(millis() - Offtime > (TimeOff * factor) && ON == false) // LED is currently off, now keep counting to turn it on.
  {
    Ontime = millis();
    digitalWrite(led, HIGH);    // turn on LED
    ON = true;
  }
}
595  Using Arduino / Project Guidance / Re: Button Help, Up, Down, Select on: March 23, 2014, 09:55:01 pm
What menu items are you referring to? All I see are printed messages on your display, what exactly is getting changed?
596  Using Arduino / Project Guidance / Re: Ultrasonic Sensor Guidance on: March 23, 2014, 09:01:58 pm
It doesn't matter if they are physically connected or not, your code is setting those pins as outputs.
597  Using Arduino / Project Guidance / Re: Ultrasonic Sensor Guidance on: March 23, 2014, 08:57:49 pm
Is led 3 and 4 connected to the digital pins 1 and 0 or A1 an A0? If yours using the serial monitor then you shouldn't have anything in the digital pins 1 and 0, otherwise you will get unwanted results in the serial monitor.
598  Using Arduino / Project Guidance / Re: trying to connect 5 8x8 matrixes only 4 work.the first 1 from left does not. on: March 23, 2014, 08:15:32 pm
Try changing this unsigned long x to unsigned long long x
599  Using Arduino / Project Guidance / Re: trying to connect 5 8x8 matrixes only 4 work.the first 1 from left does not. on: March 23, 2014, 07:43:58 pm
Do all 5 displays work now?

What exactly are you trying to do, your original question was that your 5th display wasn't working.

This here is only sending it to four displays.
Quote
void printBufferLong(){
  for (int a=0;a<7;a++){                    // Loop 7 times for a 5x7 font
    unsigned long x = bufferLong [a*2+1];   // Get high buffer entry
    byte y = x;                             // Mask off first character
    lc.setRow(3,a,y);                       // Send row to relevent MAX7219 chip
    x = bufferLong [a*2];                   // Get low buffer entry
    y = (x>>24);                            // Mask off second character
    lc.setRow(2,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>16);                            // Mask off third character
    lc.setRow(1,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>smiley-cool;                             // Mask off forth character
    lc.setRow(0,a,y);                       // Send row to relevent MAX7219 chip

  }
}

Replace it with this and see if it works. I added in:  lc.setRow(4,a,y); .... y = (x>>32);  lc.setRow(3,a,y);

Code:
void printBufferLong(){
  for (int a=0;a<7;a++){                    // Loop 7 times for a 5x7 font
    unsigned long x = bufferLong [a*2+1];   // Get high buffer entry
    byte y = x;                             // Mask off first character
    lc.setRow(4,a,y);                       // Send row to relevent MAX7219 chip
    x = bufferLong [a*2];                   // Get low buffer entry
    y = (x>>32);                            // Mask off second character
    lc.setRow(3,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>24);                            // Mask off third character
    lc.setRow(2,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>16);                            // Mask off forth character
    lc.setRow(1,a,y);                       // Send row to relevent MAX7219 chip
    y = (x>>8);                             // Mask off fifth character
    lc.setRow(0,a,y);                       // Send row to relevent MAX7219 chip
  }
}
600  Using Arduino / Project Guidance / Re: trying to connect 5 8x8 matrixes only 4 work.the first 1 from left does not. on: March 23, 2014, 01:04:49 pm
Do you have the MaxMatrix library too? Most if not all my dot matrix sketches use both the Ledcontrol and MaxMatrix libraries.

But this is one I use to see if all the displays work.
Code:
//We always have to include the library
#include "LedControl.h"

/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn
 pin 11 is connected to the CLK
 pin 10 is connected to LOAD
 ***** Please set the number of devices you have *****
 But the maximum default of 8 MAX72XX wil also work.
 */
LedControl lc=LedControl(12,11,10,4);

/* we always wait a bit between updates of the display */
unsigned long delaytime=10;
int devices;
/*
 This time we have more than one device.
 But all of them have to be initialized
 individually.
 */
void setup() {
  //we have already set the number of devices when we created the LedControl
  devices = lc.getDeviceCount();
  //we have to init all devices in a loop
  for(int address = devices - 1; address >= 0;address--)
  {
    /*The MAX72XX is in power-saving mode on startup*/
    lc.shutdown(address,false);
    /* Set the brightness to a medium values */
    lc.setIntensity(address,8);
    /* and clear the display */
    lc.clearDisplay(address);
  }
}

void loop()
{
  //we have to init all devices in a loop
  for(int address = devices - 1; address >= 0;address--)
  {
    for(int row=0;row<8;row++)
    {
      for(int col=0;col<8;col++)
      {
        delay(delaytime);
        lc.setLed(address,row,col,true);
        delay(delaytime);
        lc.setLed(address,row,col,false);
      }
    }
  }
}
Pages: 1 ... 38 39 [40] 41 42 ... 228