Show Posts
Pages: [1] 2 3 4
1  Development / Other Software Development / expected unqualified-id before if on: March 24, 2014, 12:39:43 am
I am trying to use a keypad to take the input of one key to turn a sepicific pin on. I have a total of 4 inputs, so when the person press the right button it will turn the right pin. The issue I am having is: I get "expected unqualified-id before if " . I used the switch and got the same issue. Do you know what I am doing wrong?
Here is the code that I am running:
Code:
#include <Keypad.h>
int pirPin = 8;
int NamePin = 9;
int HerePin =10;
int CvnPin = 2;
int OffPin = 11;
const byte ROWS = 3;
const byte COLS = 3;
char keys[ROWS][COLS] =
{
  {
    '1','2','3'     }
  ,
  {
    '4','5','6'     }
  ,
  {
    '7','8','9'     }
  ,

};
byte rowPins [ROWS] = {
  5, 4, 3};
byte colPins [COLS] = {
  8, 7, 6 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
  Serial.begin (9600);   
  pinMode(NamePin, OUTPUT);
  pinMode(HerePin, INPUT);   
  pinMode(CvnPin, OUTPUT);
  pinMode(OffPin, INPUT);

void handleKeypress (const char key)
{
  Serial.println (key);
}
if(key == '1')
{
  digitalWrite(NamePin, LOW);
  delay(1000);
  digitalWrite(NamePin, HIGH);
  delay(1000);

else if (key = '3')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(HerePin, HIGH);
delay(1000);
else if (key = '7')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(CvnPin, HIGH);
delay(1000);
else (key = '9')
digitalWrite(NamePin, LOW);
delay(1000);
digitalWrite(OffPin, HIGH);
delay(1000);
}
void loop()
{
  byte key = kpd.getKey();
  if (key)
    handleKeypress (key);
}
2  Development / Other Software Development / Re: Standalone on: March 14, 2014, 10:49:30 am
I live in USA. I think I'll try buying from Sparkfun this time. they are familiar to me.
Thank you for your help
3  Development / Other Software Development / Re: Standalone on: March 14, 2014, 01:36:20 am
First, thank you very much for getting back to me.
I performed the test you suggested. here is the outcome:
1- I don't think I still have the original ATMEGA328 that came with the Arduino. I bought the arduino 3 years ago and later I bought 10 ATMEGA328Ps to use in  projects that I may think about; then I stopped for a while and now I wanted to go back to Arduino, so I am not sure if I still have the original or not but I know that I used these 328 before in other circuits and worked fine. I guess I need to go back and try them again.
2- As I mentioned in a previous message I use the Arduino IDE to upload the code to the ATMEGA328P. When the upload is completed I get a message on the IDE that the upload is completed, if not it spits some errors.
3-When I uploaded your code I saw that LED near pin 13 on the Arduino blinking at a rate of 5HZ (approx.) I also opened the serial monitor to see the message and got "Hello from Arduino"
4- I pressed the reset button that is near the USB plug on the Arduino to see what will happen and didn't notice any changes except that every time you hit reset the serial monitor prints the message, the LED blinking rate was the same.
5- However when I unplug and plug the USB (Recycle power) the sketch got lost. I had to upload it to get it back to normal.
That's what I observed.
Now you made me think that maybe these 328s is the problem. I hope so.
Can you suggest a place where I can get a good 328 ; also could tell me what to look for when you buy these little devices. Thank you again. Thank you.
 
4  Development / Other Software Development / Re: Standalone on: March 13, 2014, 01:50:24 am
I am, basically, trying to implement the first example (using one shift register). The example can be seen here:
http://arduino.cc/en/tutorial/ShiftOut#.UyFRC4VRHKd
The purpose is to use it for a scroll sign but before I get there. I wanted to get the basics first.
The final project will be like this: I will use a range finder or another mention sensor and when triggered it will cause a message to scroll.
for now I just wanted to be able to get that first example working without loosing the sketch when I recycle power.
I got the 328s a while ago. I remember the seller told me they have a boot-loader installed in them and should work just like the one you buy with the Arduino.
You raised a good question. I don't know what a bootloader does and are there different bootloaders?
Thank you very much for your help.
5  Development / Other Software Development / Re: Standalone on: March 11, 2014, 11:49:14 pm
Yes! My code is only being used while the 328 is plugged into the Uno board.
What would be a meaningful title and where should I post it to get a good answer to this.
I've built small projects where I used the 328 on a breadboard but, again, I noticed that with some programs it works fine in the UNO or on the breadboard but with some programs it doesn't when you recycle power.
Thanks
6  Development / Other Software Development / Re: Standalone on: March 10, 2014, 04:16:50 pm
Thank you  smiley
I am using this: ATMEGA328P-PU
I don't know if it's a standalone microprocessor or not, I don't know how to check for that. But I know it works for other program such as a blinking LED program. It works all the time even after recycling power. Also I made a small alarm system using a range finder, LEDs and a buzzer and no issues, but I had problem with a program that I used to control a micro pump and another one involving a keypad. So I don't know if it's the code or  using the wrong microprocessor but if that's the case why it worked with some programs and not others.
To upload I use the arduino UNO. I had the microprocessor plugged in the Arduino UNO and I used the USB and my laptop to upload the software to it using the Arduino evironment.
I hope I was clear in explaining the issue and thank you for considering my post. Thanks a lot, if you help me with this you will save me a lot of headaches.
7  Development / Other Software Development / Standalone on: March 10, 2014, 01:13:49 am
Hi,
I am experimenting with shift registers and LEDs, basically turning on and off LEDs one by one (scrolling) as a first step.
I uploaded the following code to my Arduino. It worked fine (i.e. turn on and of 8 LEDs connected to the output of a shift register) however when I recycle power to the Arduino, the circuit stops working. To get it work I need to upload the code again and keep it like that, any recycling of power will require uploading the code again.
I tried few time getting help about this topic because I had this issue with other projects in the past, but so far no one provided any helpful suggestion. I hope this time someone will help. Thank you
here the code:

Code:
//Pin Definitions
// 7HC595N has three pins
int data = 2; // where we send the bits to control outputs
int clock = 3; // keeps the data in sync
int latch = 4; // tells the shift register when to activate the output sequence

void setup()
{
   // set the three control pins to output
  pinMode(data, OUTPUT);
  pinMode(clock, OUTPUT); 
  pinMode(latch, OUTPUT); 
 
  Serial.begin(9600); // so we can send debug messages to serial monitor
}

void loop(){
   
    outputBytes(); // our basic output which writes 8-bits to show how a shift register works.
    //outputIntegers(); // sends an integer value as data instead of bytes, effectively counting in binary.
}
 
void outputIntegers(){
     for (int i=0;i<256;i++){
        digitalWrite(latch, LOW);     
        Serial.println(i);  // Debug, sending output to the serial monitor
        shiftOut(data, clock, MSBFIRST, i);
        digitalWrite(latch, HIGH);   
        delay(100);   
     }
}

void outputBytes(){
    /* Bytes, or 8-bits, are represented by a B followed by 8 0 or 1s.
        In this instance, consider this to be like an array that we'll use to control
        the 8 LEDs. Here I've started the byte value as 00000001
    */   
       
    byte dataValues = B00000001; // change this to adjust the starting pattern
   
    /* In the for loop, we begin by pulling the latch low,
        using the shiftOut Arduino function to talk to the shift register,
        sending it our byte of dataValues representing the state of the LEDs
        then pull the latch high to lock those into place.
       
        Finally, we shift the bits one place to the left, meaning the next iteration
        will turn on the next LED in the series.
       
        To see the exact binary value being sent, check the serial monitor.
    */
   
    for (int i=0;i<8;i++){
      digitalWrite(latch, LOW);     
      Serial.println(dataValues, BIN);  // Debug, sending output to the serial monitor
      shiftOut(data, clock, MSBFIRST, dataValues);
      digitalWrite(latch, HIGH);   
      dataValues = dataValues << 1; // Shift the bits one place to the left -  change to >> to adjust direction
      delay(30);   
    }
 
}
8  Using Arduino / Programming Questions / Re: Code doesn't do it's job when I recycle power on: May 27, 2013, 03:59:01 pm
what you mean current limiting resistor? I don't have that. You mean for each LED I need to put a current limiting resistor in the negative side and tie it to ground. Right?
9  Using Arduino / Programming Questions / Re: Code doesn't do it's job when I recycle power on: May 27, 2013, 01:51:43 pm
The PIR and the LEDs and wires that's it.
10  Using Arduino / Programming Questions / Re: Code doesn't do it's job when I recycle power on: May 27, 2013, 01:17:53 pm
I am using an Arduino Uno.
When I upload the code the LEDs work as they are supposed to (when I come close to the pir. the pir pin turn high and LEDs start blinking. No problem smiley)
The problem is when I unplug the USB from the laptop and putting it back ; I need to upload the code again and make sure no one unplugs the USB. otherwise nothing works
11  Using Arduino / Programming Questions / Code doesn't do it's job when I recycle power on: May 26, 2013, 06:01:52 pm
I hope someone could help with this issue. when I upload the code to arduino, it works perfect: Turning 6 LEDs on and off when a pir is triggered but the issue is: once I unplug the USB and put it back again the circuit doesn't do anything so I need to upload the code again for it to work.
What could be the problem: Is it the code or the arduino resetting itself or what?
I had this issue before, but with other project it worked fine.
Here is my code:
Code:
int DL= 20;
int val = 0;
int pirPin = 8;
void setup() {
  for(int pinled =2; pinled <=7; pinled=pinled + 1)
    pinMode(pinled, OUTPUT);
  pinMode(pirPin, INPUT);
}
void loop()
{
  val = digitalRead(pirPin);

  if(HIGH == val){
    for(int pinled=2; pinled<=7; pinled ++)
    {
      digitalWrite(pinled, HIGH);
      delay(DL);
      digitalWrite(pinled,LOW);
    }
    for(int pinled=6; pinled>=2; pinled --)
    {
      digitalWrite(pinled, HIGH);
      delay(DL);
      digitalWrite(pinled,LOW);
    }
  }
}




12  Using Arduino / Programming Questions / Re: PIR: For loop inside an if statement on: May 23, 2013, 06:00:43 pm
HAHAHAH.
I like how you explained it.
13  Using Arduino / Programming Questions / Re: PIR: For loop inside an if statement on: May 23, 2013, 05:33:27 pm
I added that code to make sure the LEDs stay off.
I guess I don't need it.
14  Using Arduino / Programming Questions / Re: PIR: For loop inside an if statement on: May 23, 2013, 05:31:03 pm
Yes i tested the pir with a working code and it works very good.
15  Using Arduino / Programming Questions / Re: PIR: For loop inside an if statement on: May 23, 2013, 05:17:53 pm
When i tested the for loop by itself, it worked fine. It turns the first LED on then off and moves to next one that 's why i have that delay in my code.
but when I tried putting the for loop inside the if statement because I am using a pir sensor to trigger the LEDs when motion is sensed, it wouldn't work.
I wanted to say: when the output pin of the pir is high do the for loop which just turns the LEDs on and off in sequence as I explained else turn them off.
I hope I clarified a little bit.
Thank you
Pages: [1] 2 3 4